feat: 初始化 sundynix-agentix 分层式 AI Agent 平台脚手架
5 层 + 1 条 NATS 零拷贝消息总线的 monorepo(Monolith First → Microservices Morph B)。 纵向主干(任务流 + Token 流回流)已真实跑通,横向各层能力为带注释的桩。 已贯通(real code): - sundynix-shared: 共享契约 + JetStream/core NATS 真实收发(bus) + 内嵌 NATS(devnats) + e2e 测试 - sundynix-gateway: Gin 接入 + DSL 解析组装 + NATS Publish + SSE 流式输出 - sundynix-dispatcher: NATS 消费 + Eino Orchestrator 流式回流 + 熔断器 + LLM Pool 占位流式 - 链路: HTTP POST → DSL → sundynix.tasks.* → Dispatcher → Token 经 sundynix.streams.<id> 回流 → SSE - 基础设施: docker-compose(nats/postgres/redis/neo4j/milvus) + Makefile(make demo/e2e) 待填(桩): - Eino 图编排 compose.NewGraph、LLM Pool 接 vLLM/Ollama - Gateway store 换真实 pgx/redis - sundynix-mcp-go: Bleve+Milvus+Neo4j 混合检索 / UniOffice / 外部 API - sundynix-mcp-py: gVisor 沙箱 / MinerU(PaddleOCR) / Docker 解释器 - sundynix-desktop: React Flow 画布 → DSL 导出 → SSE 展示
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// Package contract 是 Gateway / Dispatcher / MCP 之间的共享契约:
|
||||
// Task 数据结构与 NATS subject 命名约定。
|
||||
package contract
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// NATS subject / stream 约定(与 README、各服务 config 保持一致)。
|
||||
const (
|
||||
StreamTasks = "SUNDYNIX_TASKS" // JetStream stream 名
|
||||
SubjectTasks = "sundynix.tasks" // 任务发布主题前缀;实际为 sundynix.tasks.<id>
|
||||
SubjectTasksAll = "sundynix.tasks.>" // stream 捕获的通配
|
||||
SubjectStream = "sundynix.streams" // Token 回流前缀;实际 sundynix.streams.<id>
|
||||
ConsumerDurable = "dispatchers" // Dispatcher 持久消费者(队列组负载均衡)
|
||||
|
||||
// HeaderStreamEnd 是 Token 流的结束信号(core NATS 消息头)。
|
||||
// 置为 "1" 的消息体为空,表示该 task 的 Token 流结束。
|
||||
HeaderStreamEnd = "X-Stream-End"
|
||||
)
|
||||
|
||||
// Task 是 DSL 解析组装后的可调度任务,在 NATS 上以 JSON 传输。
|
||||
type Task struct {
|
||||
ID string `json:"id"`
|
||||
Graph json.RawMessage `json:"graph"` // React Flow 导出的 Agent 编排图
|
||||
Meta map[string]any `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
// TaskSubject 返回某任务的发布主题。
|
||||
func TaskSubject(id string) string { return SubjectTasks + "." + id }
|
||||
|
||||
// StreamSubject 返回某任务的 Token 回流主题。
|
||||
func StreamSubject(id string) string { return SubjectStream + "." + id }
|
||||
|
||||
// Marshal / Unmarshal 便捷方法。
|
||||
func (t *Task) Marshal() ([]byte, error) { return json.Marshal(t) }
|
||||
func Unmarshal(b []byte) (*Task, error) {
|
||||
var t Task
|
||||
if err := json.Unmarshal(b, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &t, nil
|
||||
}
|
||||
Reference in New Issue
Block a user