Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
82 lines
2.8 KiB
Go
82 lines
2.8 KiB
Go
package agentruntime
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
|
|
agentsessionstore "github.com/tutti-os/tutti/packages/agent/daemon/activity"
|
|
)
|
|
|
|
type durableGoalProvenanceReporter interface {
|
|
BindGoalProvenance(context.Context, agentsessionstore.BindGoalProvenanceInput) (agentsessionstore.GoalProvenanceBinding, error)
|
|
LookupGoalProvenance(context.Context, agentsessionstore.LookupGoalProvenanceInput) (agentsessionstore.GoalProvenanceBinding, bool, error)
|
|
}
|
|
|
|
func (c *Controller) BindGoalProvenance(
|
|
ctx context.Context,
|
|
session Session,
|
|
fingerprint string,
|
|
binding GoalProvenanceBinding,
|
|
) (GoalProvenanceBinding, error) {
|
|
if session.IsSideConversation() {
|
|
return GoalProvenanceBinding{}, ErrSideConversationUnsupported
|
|
}
|
|
reporter, ok := c.goalProvenanceReporter()
|
|
if !ok {
|
|
return GoalProvenanceBinding{}, errors.New("durable goal provenance reporter is unavailable")
|
|
}
|
|
durable, err := reporter.BindGoalProvenance(ctx, agentsessionstore.BindGoalProvenanceInput{
|
|
WorkspaceID: session.RoomID, AgentSessionID: session.AgentSessionID,
|
|
SessionCreatedAtUnixMS: session.CreatedAtUnixMS,
|
|
ProviderSessionID: session.ProviderSessionID, Fingerprint: strings.TrimSpace(fingerprint),
|
|
OperationID: binding.OperationID, Revision: binding.Revision, RepairEpoch: binding.RepairEpoch,
|
|
OccurredAtUnixMS: time.Now().UnixMilli(),
|
|
})
|
|
if err != nil {
|
|
return GoalProvenanceBinding{}, err
|
|
}
|
|
return runtimeGoalProvenanceBinding(durable), nil
|
|
}
|
|
|
|
func (c *Controller) LookupGoalProvenance(
|
|
ctx context.Context,
|
|
session Session,
|
|
fingerprint string,
|
|
) (GoalProvenanceBinding, bool, error) {
|
|
if session.IsSideConversation() {
|
|
return GoalProvenanceBinding{}, false, ErrSideConversationUnsupported
|
|
}
|
|
reporter, ok := c.goalProvenanceReporter()
|
|
if !ok {
|
|
return GoalProvenanceBinding{}, false, errors.New("durable goal provenance reporter is unavailable")
|
|
}
|
|
durable, found, err := reporter.LookupGoalProvenance(ctx, agentsessionstore.LookupGoalProvenanceInput{
|
|
WorkspaceID: session.RoomID, AgentSessionID: session.AgentSessionID,
|
|
SessionCreatedAtUnixMS: session.CreatedAtUnixMS,
|
|
ProviderSessionID: session.ProviderSessionID, Fingerprint: strings.TrimSpace(fingerprint),
|
|
})
|
|
if err != nil || !found {
|
|
return GoalProvenanceBinding{}, found, err
|
|
}
|
|
return runtimeGoalProvenanceBinding(durable), true, nil
|
|
}
|
|
|
|
func (c *Controller) goalProvenanceReporter() (durableGoalProvenanceReporter, bool) {
|
|
if c == nil || c.reporter == nil {
|
|
return nil, false
|
|
}
|
|
reporter, ok := c.reporter.(durableGoalProvenanceReporter)
|
|
return reporter, ok
|
|
}
|
|
|
|
func runtimeGoalProvenanceBinding(binding agentsessionstore.GoalProvenanceBinding) GoalProvenanceBinding {
|
|
return GoalProvenanceBinding{
|
|
OperationID: binding.OperationID,
|
|
Revision: binding.Revision,
|
|
RepairEpoch: binding.RepairEpoch,
|
|
Ambiguous: binding.Ambiguous,
|
|
}
|
|
}
|