Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a862a07ae1 | ||
|
|
4d63c1bea4 | ||
|
|
91c38de167 | ||
|
|
926afc82b5 |
@@ -11,7 +11,7 @@ import (
|
|||||||
type AuthorityRepository struct{ pool *pgxpool.Pool }
|
type AuthorityRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenAuthority(ctx context.Context, c ContinuityConfig) (*AuthorityRepository, error) {
|
func OpenAuthority(ctx context.Context, c ContinuityConfig) (*AuthorityRepository, error) {
|
||||||
p, e := pgxpool.New(ctx, fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", c.Host, c.Port, c.Database, c.User, c.Password))
|
p, e := openPool(ctx, c)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ var ErrCapabilityImplementationNotFound = errors.New("capability implementation
|
|||||||
type CapabilityRepository struct{ pool *pgxpool.Pool }
|
type CapabilityRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenCapability(ctx context.Context, config ContinuityConfig) (*CapabilityRepository, error) {
|
func OpenCapability(ctx context.Context, config ContinuityConfig) (*CapabilityRepository, error) {
|
||||||
dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password)
|
pool, err := openPool(ctx, config)
|
||||||
pool, err := pgxpool.New(ctx, dsn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ var (
|
|||||||
type CommitRepository struct{ pool *pgxpool.Pool }
|
type CommitRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenCommit(ctx context.Context, c ContinuityConfig) (*CommitRepository, error) {
|
func OpenCommit(ctx context.Context, c ContinuityConfig) (*CommitRepository, error) {
|
||||||
p, e := pgxpool.New(ctx, fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", c.Host, c.Port, c.Database, c.User, c.Password))
|
p, e := openPool(ctx, c)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"git.cin.su/m/Assistant/contracts/authority"
|
"git.cin.su/m/Assistant/contracts/authority"
|
||||||
"git.cin.su/m/Assistant/contracts/continuity"
|
"git.cin.su/m/Assistant/contracts/continuity"
|
||||||
@@ -29,9 +30,25 @@ var (
|
|||||||
type ContinuityConfig struct{ Host, Port, Database, User, Password string }
|
type ContinuityConfig struct{ Host, Port, Database, User, Password string }
|
||||||
type ContinuityRepository struct{ pool *pgxpool.Pool }
|
type ContinuityRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
|
func openPool(ctx context.Context, config ContinuityConfig) (*pgxpool.Pool, error) {
|
||||||
|
poolConfig, err := pgxpool.ParseConfig("")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
port, err := strconv.ParseUint(config.Port, 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid postgres port: %w", err)
|
||||||
|
}
|
||||||
|
poolConfig.ConnConfig.Host = config.Host
|
||||||
|
poolConfig.ConnConfig.Port = uint16(port)
|
||||||
|
poolConfig.ConnConfig.Database = config.Database
|
||||||
|
poolConfig.ConnConfig.User = config.User
|
||||||
|
poolConfig.ConnConfig.Password = config.Password
|
||||||
|
return pgxpool.NewWithConfig(ctx, poolConfig)
|
||||||
|
}
|
||||||
|
|
||||||
func OpenContinuity(ctx context.Context, config ContinuityConfig) (*ContinuityRepository, error) {
|
func OpenContinuity(ctx context.Context, config ContinuityConfig) (*ContinuityRepository, error) {
|
||||||
dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password)
|
pool, err := openPool(ctx, config)
|
||||||
pool, err := pgxpool.New(ctx, dsn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ import (
|
|||||||
type EpistemicsRepository struct{ pool *pgxpool.Pool }
|
type EpistemicsRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenEpistemics(ctx context.Context, config ContinuityConfig) (*EpistemicsRepository, error) {
|
func OpenEpistemics(ctx context.Context, config ContinuityConfig) (*EpistemicsRepository, error) {
|
||||||
dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password)
|
pool, err := openPool(ctx, config)
|
||||||
pool, err := pgxpool.New(ctx, dsn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
type IdentityRepository struct{ pool *pgxpool.Pool }
|
type IdentityRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenIdentity(ctx context.Context, config ContinuityConfig) (*IdentityRepository, error) {
|
func OpenIdentity(ctx context.Context, config ContinuityConfig) (*IdentityRepository, error) {
|
||||||
pool, err := pgxpool.New(ctx, fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password))
|
pool, err := openPool(ctx, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package postgres
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.cin.su/m/Assistant/contracts/interaction"
|
"git.cin.su/m/Assistant/contracts/interaction"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
@@ -11,7 +10,7 @@ import (
|
|||||||
type InteractionRepository struct{ pool *pgxpool.Pool }
|
type InteractionRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenInteraction(ctx context.Context, c ContinuityConfig) (*InteractionRepository, error) {
|
func OpenInteraction(ctx context.Context, c ContinuityConfig) (*InteractionRepository, error) {
|
||||||
p, e := pgxpool.New(ctx, fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", c.Host, c.Port, c.Database, c.User, c.Password))
|
p, e := openPool(ctx, c)
|
||||||
return &InteractionRepository{p}, e
|
return &InteractionRepository{p}, e
|
||||||
}
|
}
|
||||||
func (r *InteractionRepository) Close() { r.pool.Close() }
|
func (r *InteractionRepository) Close() { r.pool.Close() }
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package postgres
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.cin.su/m/Assistant/contracts/identity"
|
"git.cin.su/m/Assistant/contracts/identity"
|
||||||
@@ -13,8 +12,7 @@ import (
|
|||||||
type SituationRepository struct{ pool *pgxpool.Pool }
|
type SituationRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenSituation(ctx context.Context, config ContinuityConfig) (*SituationRepository, error) {
|
func OpenSituation(ctx context.Context, config ContinuityConfig) (*SituationRepository, error) {
|
||||||
dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password)
|
pool, err := openPool(ctx, config)
|
||||||
pool, err := pgxpool.New(ctx, dsn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ import (
|
|||||||
type WorkRepository struct{ pool *pgxpool.Pool }
|
type WorkRepository struct{ pool *pgxpool.Pool }
|
||||||
|
|
||||||
func OpenWork(ctx context.Context, config ContinuityConfig) (*WorkRepository, error) {
|
func OpenWork(ctx context.Context, config ContinuityConfig) (*WorkRepository, error) {
|
||||||
dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password)
|
pool, err := openPool(ctx, config)
|
||||||
pool, err := pgxpool.New(ctx, dsn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -85,7 +86,12 @@ func (r learningRecorder) recordReminderResponse(ctx context.Context, input remi
|
|||||||
RecordedAtUnixMillis: input.At.UnixMilli(),
|
RecordedAtUnixMillis: input.At.UnixMilli(),
|
||||||
}
|
}
|
||||||
expectation, err := epistemicsdomain.NewSystemExpectation(expectation)
|
expectation, err := epistemicsdomain.NewSystemExpectation(expectation)
|
||||||
if err != nil || r.epistemics.SaveSystemExpectation(ctx, expectation) != nil {
|
if err != nil {
|
||||||
|
log.Printf("learning reminder expectation invalid: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := r.epistemics.SaveSystemExpectation(ctx, expectation); err != nil {
|
||||||
|
log.Printf("learning reminder expectation unavailable: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
actual, confidence := outcomeForHumanResponse(input.Result.Response)
|
actual, confidence := outcomeForHumanResponse(input.Result.Response)
|
||||||
@@ -197,13 +203,19 @@ func (r learningRecorder) recordCapabilityUse(ctx context.Context, input capabil
|
|||||||
func (r learningRecorder) saveExperienceAndReflection(ctx context.Context, value epistemics.ExperienceRecord) (epistemics.ExperienceRecord, bool) {
|
func (r learningRecorder) saveExperienceAndReflection(ctx context.Context, value epistemics.ExperienceRecord) (epistemics.ExperienceRecord, bool) {
|
||||||
value, err := epistemicsdomain.NewExperienceRecord(value)
|
value, err := epistemicsdomain.NewExperienceRecord(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("learning experience invalid: %v", err)
|
||||||
return epistemics.ExperienceRecord{}, false
|
return epistemics.ExperienceRecord{}, false
|
||||||
}
|
}
|
||||||
if err := r.epistemics.SaveExperienceRecord(ctx, value); err != nil {
|
if err := r.epistemics.SaveExperienceRecord(ctx, value); err != nil {
|
||||||
|
log.Printf("learning experience unavailable: %v", err)
|
||||||
return epistemics.ExperienceRecord{}, false
|
return epistemics.ExperienceRecord{}, false
|
||||||
}
|
}
|
||||||
if candidate, ok, err := epistemicsdomain.ReflectionForExperience(value); err == nil && ok {
|
if candidate, ok, err := epistemicsdomain.ReflectionForExperience(value); err == nil && ok {
|
||||||
_ = r.epistemics.SaveReflectionCandidate(ctx, candidate)
|
if err := r.epistemics.SaveReflectionCandidate(ctx, candidate); err != nil {
|
||||||
|
log.Printf("learning reflection unavailable: %v", err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
log.Printf("learning reflection invalid: %v", err)
|
||||||
}
|
}
|
||||||
return value, true
|
return value, true
|
||||||
}
|
}
|
||||||
@@ -214,6 +226,7 @@ func (r learningRecorder) updateReminderSkill(ctx context.Context, experience ep
|
|||||||
}
|
}
|
||||||
profile, err := r.capability.LoadSkillProfile(ctx, reminderResponseSkillID)
|
profile, err := r.capability.LoadSkillProfile(ctx, reminderResponseSkillID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("learning skill profile unavailable: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
next, err := capabilitydomain.ObserveSkillOutcome(profile, capability.SkillOutcomeObservation{
|
next, err := capabilitydomain.ObserveSkillOutcome(profile, capability.SkillOutcomeObservation{
|
||||||
@@ -223,9 +236,11 @@ func (r learningRecorder) updateReminderSkill(ctx context.Context, experience ep
|
|||||||
ObservedAtUnixMillis: experience.RecordedAtUnixMillis,
|
ObservedAtUnixMillis: experience.RecordedAtUnixMillis,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("learning skill observation invalid: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := r.capability.SaveSkillProfile(ctx, next); err != nil {
|
if err := r.capability.SaveSkillProfile(ctx, next); err != nil {
|
||||||
|
log.Printf("learning skill profile save unavailable: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user