mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-09-28 04:01:54 +02:00
Add files via upload
This commit is contained in:
@@ -226,6 +226,10 @@ func (db *DB) initTables() error {
|
|||||||
start_time DATETIME NOT NULL,
|
start_time DATETIME NOT NULL,
|
||||||
end_time DATETIME,
|
end_time DATETIME,
|
||||||
duration_ms INTEGER,
|
duration_ms INTEGER,
|
||||||
|
partial_output TEXT,
|
||||||
|
partial_output_bytes INTEGER NOT NULL DEFAULT 0,
|
||||||
|
partial_output_truncated INTEGER NOT NULL DEFAULT 0,
|
||||||
|
partial_output_updated_at DATETIME,
|
||||||
owner_user_id TEXT,
|
owner_user_id TEXT,
|
||||||
conversation_id TEXT,
|
conversation_id TEXT,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
@@ -954,6 +958,9 @@ func (db *DB) initTables() error {
|
|||||||
if err := db.migrateWorkflowRunsTable(); err != nil {
|
if err := db.migrateWorkflowRunsTable(); err != nil {
|
||||||
db.logger.Warn("迁移workflow_runs表失败", zap.Error(err))
|
db.logger.Warn("迁移workflow_runs表失败", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
if err := db.migrateToolExecutionsPartialOutputColumns(); err != nil {
|
||||||
|
db.logger.Warn("迁移tool_executions partial output字段失败", zap.Error(err))
|
||||||
|
}
|
||||||
if err := db.migrateRBACOwnershipColumns(); err != nil {
|
if err := db.migrateRBACOwnershipColumns(); err != nil {
|
||||||
db.logger.Warn("迁移RBAC资源归属字段失败", zap.Error(err))
|
db.logger.Warn("迁移RBAC资源归属字段失败", zap.Error(err))
|
||||||
}
|
}
|
||||||
@@ -978,6 +985,23 @@ func (db *DB) migrateRobotUserSessionsTable() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) migrateToolExecutionsPartialOutputColumns() error {
|
||||||
|
for _, col := range []struct {
|
||||||
|
name string
|
||||||
|
stmt string
|
||||||
|
}{
|
||||||
|
{"partial_output", "ALTER TABLE tool_executions ADD COLUMN partial_output TEXT"},
|
||||||
|
{"partial_output_bytes", "ALTER TABLE tool_executions ADD COLUMN partial_output_bytes INTEGER NOT NULL DEFAULT 0"},
|
||||||
|
{"partial_output_truncated", "ALTER TABLE tool_executions ADD COLUMN partial_output_truncated INTEGER NOT NULL DEFAULT 0"},
|
||||||
|
{"partial_output_updated_at", "ALTER TABLE tool_executions ADD COLUMN partial_output_updated_at DATETIME"},
|
||||||
|
} {
|
||||||
|
if err := db.addColumnIfMissing("tool_executions", col.name, col.stmt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// migrateAssetsTable keeps databases created by the first asset-management release compatible.
|
// migrateAssetsTable keeps databases created by the first asset-management release compatible.
|
||||||
func (db *DB) migrateAssetsTable() error {
|
func (db *DB) migrateAssetsTable() error {
|
||||||
columns := []struct {
|
columns := []struct {
|
||||||
|
|||||||
@@ -43,11 +43,19 @@ func (db *DB) SaveToolExecution(exec *mcp.ToolExecution) error {
|
|||||||
if exec.Duration > 0 {
|
if exec.Duration > 0 {
|
||||||
durationMs = sql.NullInt64{Int64: exec.Duration.Milliseconds(), Valid: true}
|
durationMs = sql.NullInt64{Int64: exec.Duration.Milliseconds(), Valid: true}
|
||||||
}
|
}
|
||||||
|
var partialUpdatedAt sql.NullTime
|
||||||
|
if exec.PartialOutputUpdatedAt != nil {
|
||||||
|
partialUpdatedAt = sql.NullTime{Time: *exec.PartialOutputUpdatedAt, Valid: true}
|
||||||
|
}
|
||||||
|
partialTruncated := 0
|
||||||
|
if exec.PartialOutputTruncated {
|
||||||
|
partialTruncated = 1
|
||||||
|
}
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
INSERT OR REPLACE INTO tool_executions
|
INSERT OR REPLACE INTO tool_executions
|
||||||
(id, tool_name, arguments, status, result, error, start_time, end_time, duration_ms, owner_user_id, conversation_id, created_at)
|
(id, tool_name, arguments, status, result, error, start_time, end_time, duration_ms, partial_output, partial_output_bytes, partial_output_truncated, partial_output_updated_at, owner_user_id, conversation_id, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
`
|
`
|
||||||
|
|
||||||
_, err = db.Exec(query,
|
_, err = db.Exec(query,
|
||||||
@@ -60,6 +68,10 @@ func (db *DB) SaveToolExecution(exec *mcp.ToolExecution) error {
|
|||||||
exec.StartTime,
|
exec.StartTime,
|
||||||
endTime,
|
endTime,
|
||||||
durationMs,
|
durationMs,
|
||||||
|
sqlNullString(exec.PartialOutput),
|
||||||
|
exec.PartialOutputBytes,
|
||||||
|
partialTruncated,
|
||||||
|
partialUpdatedAt,
|
||||||
strings.TrimSpace(exec.OwnerUserID),
|
strings.TrimSpace(exec.OwnerUserID),
|
||||||
strings.TrimSpace(exec.ConversationID),
|
strings.TrimSpace(exec.ConversationID),
|
||||||
time.Now(),
|
time.Now(),
|
||||||
@@ -90,6 +102,13 @@ func (db *DB) UpdateToolExecutionResult(id string, result *mcp.ToolResult) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sqlNullString(s string) sql.NullString {
|
||||||
|
if s == "" {
|
||||||
|
return sql.NullString{}
|
||||||
|
}
|
||||||
|
return sql.NullString{String: s, Valid: true}
|
||||||
|
}
|
||||||
|
|
||||||
// CountToolExecutions 统计工具执行记录总数
|
// CountToolExecutions 统计工具执行记录总数
|
||||||
func (db *DB) CountToolExecutions(status, toolName string) (int, error) {
|
func (db *DB) CountToolExecutions(status, toolName string) (int, error) {
|
||||||
return db.CountToolExecutionsForAccess(status, toolName, RBACListAccess{Scope: RBACScopeAll})
|
return db.CountToolExecutionsForAccess(status, toolName, RBACListAccess{Scope: RBACScopeAll})
|
||||||
@@ -488,7 +507,9 @@ func appendToolExecutionAccessSQL(query string, args []interface{}, access RBACL
|
|||||||
// GetToolExecution 根据ID获取单条工具执行记录
|
// GetToolExecution 根据ID获取单条工具执行记录
|
||||||
func (db *DB) GetToolExecution(id string) (*mcp.ToolExecution, error) {
|
func (db *DB) GetToolExecution(id string) (*mcp.ToolExecution, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT id, tool_name, arguments, status, result, error, start_time, end_time, duration_ms, COALESCE(owner_user_id, ''), COALESCE(conversation_id, '')
|
SELECT id, tool_name, arguments, status, result, error, start_time, end_time, duration_ms,
|
||||||
|
COALESCE(partial_output, ''), COALESCE(partial_output_bytes, 0), COALESCE(partial_output_truncated, 0), partial_output_updated_at,
|
||||||
|
COALESCE(owner_user_id, ''), COALESCE(conversation_id, '')
|
||||||
FROM tool_executions
|
FROM tool_executions
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`
|
`
|
||||||
@@ -501,6 +522,8 @@ func (db *DB) GetToolExecution(id string) (*mcp.ToolExecution, error) {
|
|||||||
var errorText sql.NullString
|
var errorText sql.NullString
|
||||||
var endTime sql.NullTime
|
var endTime sql.NullTime
|
||||||
var durationMs sql.NullInt64
|
var durationMs sql.NullInt64
|
||||||
|
var partialTruncated int
|
||||||
|
var partialUpdatedAt sql.NullTime
|
||||||
|
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&exec.ID,
|
&exec.ID,
|
||||||
@@ -512,6 +535,10 @@ func (db *DB) GetToolExecution(id string) (*mcp.ToolExecution, error) {
|
|||||||
&exec.StartTime,
|
&exec.StartTime,
|
||||||
&endTime,
|
&endTime,
|
||||||
&durationMs,
|
&durationMs,
|
||||||
|
&exec.PartialOutput,
|
||||||
|
&exec.PartialOutputBytes,
|
||||||
|
&partialTruncated,
|
||||||
|
&partialUpdatedAt,
|
||||||
&exec.OwnerUserID,
|
&exec.OwnerUserID,
|
||||||
&exec.ConversationID,
|
&exec.ConversationID,
|
||||||
)
|
)
|
||||||
@@ -544,6 +571,10 @@ func (db *DB) GetToolExecution(id string) (*mcp.ToolExecution, error) {
|
|||||||
if durationMs.Valid {
|
if durationMs.Valid {
|
||||||
exec.Duration = time.Duration(durationMs.Int64) * time.Millisecond
|
exec.Duration = time.Duration(durationMs.Int64) * time.Millisecond
|
||||||
}
|
}
|
||||||
|
exec.PartialOutputTruncated = partialTruncated != 0
|
||||||
|
if partialUpdatedAt.Valid {
|
||||||
|
exec.PartialOutputUpdatedAt = &partialUpdatedAt.Time
|
||||||
|
}
|
||||||
|
|
||||||
return &exec, nil
|
return &exec, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user