Files
CyberStrikeAI/internal/agentruntime/session_lock.go
T
Sycun cfaa95d7bd refactor(runtime): remove Eino and make Pi the sole agent engine
Delete the Eino model adapters, callbacks, middleware, orchestration,
summarization and single-agent runner together with their dependencies.
Chat, batch tasks, workflow Agent nodes and sub-agents now share the Pi
runtime, and dispatch is a single code path instead of an engine switch.

Configuration migrates eino_middleware/eino_skills to runtime/skills and
drops the retired callback settings while old files still load. Settings,
i18n and docs describe Pi only. Also carry the Pi follow-up fixes: empty
required lists are omitted from tool schemas, historical tool results stay
with their call batch, model proxies work over HTTP/1.1, single-query
retrieval skips query expansion, and finalization docs match Pi lifecycle
events.
2026-11-12 17:55:36 +08:00

56 lines
1.1 KiB
Go

package agentruntime
import (
"context"
"crypto/sha256"
"fmt"
"path/filepath"
"sync"
)
// ConversationStorageKey keeps every session/child scope for a conversation under one cleanup boundary.
func ConversationStorageKey(conversationID string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(conversationID)))
}
type sessionLock struct {
token chan struct{}
refs int
}
var sessionLockMu sync.Mutex
var sessionLocks = map[string]*sessionLock{}
func acquireSession(ctx context.Context, dir string) (func(), error) {
if dir == "" {
return func() {}, nil
}
key, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
sessionLockMu.Lock()
lock := sessionLocks[key]
if lock == nil {
lock = &sessionLock{token: make(chan struct{}, 1)}
sessionLocks[key] = lock
}
lock.refs++
sessionLockMu.Unlock()
remove := func() {
sessionLockMu.Lock()
defer sessionLockMu.Unlock()
lock.refs--
if lock.refs == 0 {
delete(sessionLocks, key)
}
}
select {
case lock.token <- struct{}{}:
return func() { <-lock.token; remove() }, nil
case <-ctx.Done():
remove()
return nil, ctx.Err()
}
}