灵隙(synapse) v1.0.0 版本
This commit is contained in:
@@ -79,6 +79,9 @@ func (h *ExternalAPIHandler) RegisterRoutes(mux *http.ServeMux, prefix string) {
|
||||
|
||||
// 多部分表单提交
|
||||
mux.HandleFunc(prefix+"/task/multipart", h.withAuth(h.handleTaskMultipart))
|
||||
|
||||
// 能力查询
|
||||
mux.HandleFunc(prefix+"/capabilities", h.withAuth(h.handleCapabilities))
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@@ -403,6 +406,91 @@ func (h *ExternalAPIHandler) handleTaskList(w http.ResponseWriter, r *http.Reque
|
||||
})
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 能力查询
|
||||
// =============================================================================
|
||||
|
||||
// CapabilitiesProvider 能力提供者接口
|
||||
type CapabilitiesProvider interface {
|
||||
GetCapabilities(ctx context.Context) (*CapabilitiesInfo, error)
|
||||
}
|
||||
|
||||
// CapabilitiesInfo 能力信息
|
||||
type CapabilitiesInfo struct {
|
||||
AgentID string `json:"agent_id"`
|
||||
AgentName string `json:"agent_name"`
|
||||
SystemID string `json:"system_id"`
|
||||
ProtocolVersion string `json:"protocol_version"`
|
||||
SupportedTaskTypes []SupportedTaskType `json:"supported_task_types"`
|
||||
SupportedContentTypes []string `json:"supported_content_types"`
|
||||
SupportedTransportModes []string `json:"supported_transport_modes"`
|
||||
MaxFileSize int64 `json:"max_file_size"`
|
||||
MaxConcurrentTasks int `json:"max_concurrent_tasks"`
|
||||
MaxTaskDuration int `json:"max_task_duration_seconds"`
|
||||
SupportProgressUpdates bool `json:"support_progress_updates"`
|
||||
SupportStreaming bool `json:"support_streaming"`
|
||||
SupportHiL bool `json:"support_hil"`
|
||||
SupportGroups bool `json:"support_groups"`
|
||||
}
|
||||
|
||||
// SupportedTaskType 支持的任务类型
|
||||
type SupportedTaskType struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
EstimatedTime string `json:"estimated_time"`
|
||||
InputSchema string `json:"input_schema,omitempty"`
|
||||
OutputSchema string `json:"output_schema,omitempty"`
|
||||
Capabilities []string `json:"capabilities,omitempty"`
|
||||
}
|
||||
|
||||
// CapabilitiesProviderField 能力提供者字段(可选注入)
|
||||
var CapabilitiesProviderField CapabilitiesProvider
|
||||
|
||||
func (h *ExternalAPIHandler) handleCapabilities(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
h.writeError(w, http.StatusMethodNotAllowed, "method_not_allowed", "only GET is supported")
|
||||
return
|
||||
}
|
||||
|
||||
// 如果有注入的能力提供者,使用它
|
||||
if CapabilitiesProviderField != nil {
|
||||
caps, err := CapabilitiesProviderField.GetCapabilities(r.Context())
|
||||
if err != nil {
|
||||
h.writeError(w, http.StatusInternalServerError, "capabilities_error", err.Error())
|
||||
return
|
||||
}
|
||||
h.writeJSON(w, http.StatusOK, map[string]any{
|
||||
"success": true,
|
||||
"capabilities": caps,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 默认能力信息
|
||||
caps := &CapabilitiesInfo{
|
||||
AgentID: "synapse-agent",
|
||||
AgentName: "Synapse Agent",
|
||||
SystemID: "synapse",
|
||||
ProtocolVersion: "1.0.0",
|
||||
SupportedTaskTypes: []SupportedTaskType{},
|
||||
SupportedContentTypes: []string{"application/json", "text/plain", "application/octet-stream"},
|
||||
SupportedTransportModes: []string{"callback", "polling"},
|
||||
MaxFileSize: h.MaxFileSize,
|
||||
MaxConcurrentTasks: 10,
|
||||
MaxTaskDuration: 300,
|
||||
SupportProgressUpdates: true,
|
||||
SupportStreaming: false,
|
||||
SupportHiL: true,
|
||||
SupportGroups: true,
|
||||
}
|
||||
|
||||
h.writeJSON(w, http.StatusOK, map[string]any{
|
||||
"success": true,
|
||||
"capabilities": caps,
|
||||
})
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 回调发送器
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user