Feature 09: AI harness and skills framework (#62)
Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #62.
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: ai_runs.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const clearSuggestionBatchAIRunsBefore = `-- name: ClearSuggestionBatchAIRunsBefore :execrows
|
||||
UPDATE suggestion_batches
|
||||
SET ai_run_id = NULL
|
||||
WHERE ai_run_id IN (SELECT ai_runs.id FROM ai_runs WHERE ai_runs.created_at < ?1)
|
||||
`
|
||||
|
||||
// Drops references to the runs created before the cutoff, so the purge
|
||||
// can delete them.
|
||||
func (q *Queries) ClearSuggestionBatchAIRunsBefore(ctx context.Context, cutoff string) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, clearSuggestionBatchAIRunsBefore, cutoff)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const clearWeekPlanAIRunsBefore = `-- name: ClearWeekPlanAIRunsBefore :execrows
|
||||
UPDATE week_plans
|
||||
SET ai_run_id = NULL
|
||||
WHERE ai_run_id IN (SELECT ai_runs.id FROM ai_runs WHERE ai_runs.created_at < ?1)
|
||||
`
|
||||
|
||||
// Drops references to the runs created before the cutoff, so the purge
|
||||
// can delete them.
|
||||
func (q *Queries) ClearWeekPlanAIRunsBefore(ctx context.Context, cutoff string) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, clearWeekPlanAIRunsBefore, cutoff)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const createAIRun = `-- name: CreateAIRun :exec
|
||||
INSERT INTO ai_runs (
|
||||
id, skill, skill_version, provider, model, temperature, status,
|
||||
latency_ms, tokens_in, tokens_out, error, request_redacted,
|
||||
response_redacted, created_at, updated_at
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
?, ?, ?
|
||||
)
|
||||
`
|
||||
|
||||
type CreateAIRunParams struct {
|
||||
ID string
|
||||
Skill string
|
||||
SkillVersion string
|
||||
Provider string
|
||||
Model string
|
||||
Temperature float64
|
||||
Status string
|
||||
LatencyMs sql.NullInt64
|
||||
TokensIn sql.NullInt64
|
||||
TokensOut sql.NullInt64
|
||||
Error sql.NullString
|
||||
RequestRedacted string
|
||||
ResponseRedacted sql.NullString
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAIRun(ctx context.Context, arg CreateAIRunParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createAIRun,
|
||||
arg.ID,
|
||||
arg.Skill,
|
||||
arg.SkillVersion,
|
||||
arg.Provider,
|
||||
arg.Model,
|
||||
arg.Temperature,
|
||||
arg.Status,
|
||||
arg.LatencyMs,
|
||||
arg.TokensIn,
|
||||
arg.TokensOut,
|
||||
arg.Error,
|
||||
arg.RequestRedacted,
|
||||
arg.ResponseRedacted,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteAIRunsBefore = `-- name: DeleteAIRunsBefore :execrows
|
||||
DELETE FROM ai_runs
|
||||
WHERE created_at < ?1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAIRunsBefore(ctx context.Context, cutoff string) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, deleteAIRunsBefore, cutoff)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: household_context.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const listPlannedDinners = `-- name: ListPlannedDinners :many
|
||||
SELECT plan_days.date, dinners.name
|
||||
FROM plan_days
|
||||
JOIN dinners ON dinners.id = plan_days.dinner_id
|
||||
WHERE plan_days.date >= ?1 AND plan_days.date < ?2
|
||||
ORDER BY plan_days.date, plan_days.id
|
||||
`
|
||||
|
||||
type ListPlannedDinnersParams struct {
|
||||
FromDate string
|
||||
ToDate string
|
||||
}
|
||||
|
||||
type ListPlannedDinnersRow struct {
|
||||
Date string
|
||||
Name string
|
||||
}
|
||||
|
||||
// The planned dinners dated from from_date up to but not including
|
||||
// to_date, oldest first. Days with no dinner are left out.
|
||||
func (q *Queries) ListPlannedDinners(ctx context.Context, arg ListPlannedDinnersParams) ([]ListPlannedDinnersRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listPlannedDinners, arg.FromDate, arg.ToDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListPlannedDinnersRow
|
||||
for rows.Next() {
|
||||
var i ListPlannedDinnersRow
|
||||
if err := rows.Scan(&i.Date, &i.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listRecentDeclinedNames = `-- name: ListRecentDeclinedNames :many
|
||||
|
||||
SELECT dinners.name
|
||||
FROM suggestions
|
||||
JOIN dinners ON dinners.id = suggestions.dinner_id
|
||||
WHERE suggestions.status = 'declined'
|
||||
ORDER BY suggestions.decided_at DESC, suggestions.id DESC
|
||||
LIMIT ?
|
||||
`
|
||||
|
||||
// Reads for the AI household context block (internal/ai/harness).
|
||||
// The names of the most recently declined suggestions, newest first.
|
||||
func (q *Queries) ListRecentDeclinedNames(ctx context.Context, limit int64) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listRecentDeclinedNames, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var name string
|
||||
if err := rows.Scan(&name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, name)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -15,11 +15,19 @@ type Querier interface {
|
||||
// Marks the oldest queued job running and returns it. Returns sql.ErrNoRows
|
||||
// when no job is queued.
|
||||
ClaimNextJob(ctx context.Context, now sql.NullString) (Job, error)
|
||||
// Drops references to the runs created before the cutoff, so the purge
|
||||
// can delete them.
|
||||
ClearSuggestionBatchAIRunsBefore(ctx context.Context, cutoff string) (int64, error)
|
||||
// Drops references to the runs created before the cutoff, so the purge
|
||||
// can delete them.
|
||||
ClearWeekPlanAIRunsBefore(ctx context.Context, cutoff string) (int64, error)
|
||||
CreateAIRun(ctx context.Context, arg CreateAIRunParams) error
|
||||
CreateDinner(ctx context.Context, arg CreateDinnerParams) (Dinner, error)
|
||||
CreateJob(ctx context.Context, arg CreateJobParams) error
|
||||
CreatePhoto(ctx context.Context, arg CreatePhotoParams) (Photo, error)
|
||||
CreateRecipeIngredient(ctx context.Context, arg CreateRecipeIngredientParams) error
|
||||
CreateRecipeStep(ctx context.Context, arg CreateRecipeStepParams) error
|
||||
DeleteAIRunsBefore(ctx context.Context, cutoff string) (int64, error)
|
||||
DeleteRecipeIngredients(ctx context.Context, recipeID string) error
|
||||
DeleteRecipeSteps(ctx context.Context, recipeID string) error
|
||||
FailJob(ctx context.Context, arg FailJobParams) (int64, error)
|
||||
@@ -43,6 +51,12 @@ type Querier interface {
|
||||
// Returns sql.ErrNoRows until the row exists.
|
||||
GetRecipeSearchSettings(ctx context.Context) (RecipeSearchSetting, error)
|
||||
ListDinnersByStatus(ctx context.Context, status string) ([]Dinner, error)
|
||||
// The planned dinners dated from from_date up to but not including
|
||||
// to_date, oldest first. Days with no dinner are left out.
|
||||
ListPlannedDinners(ctx context.Context, arg ListPlannedDinnersParams) ([]ListPlannedDinnersRow, error)
|
||||
// Reads for the AI household context block (internal/ai/harness).
|
||||
// The names of the most recently declined suggestions, newest first.
|
||||
ListRecentDeclinedNames(ctx context.Context, limit int64) ([]string, error)
|
||||
ListRecipeIngredients(ctx context.Context, recipeID string) ([]RecipeIngredient, error)
|
||||
ListRecipeSteps(ctx context.Context, recipeID string) ([]RecipeStep, error)
|
||||
// Stores a partial result of a running job.
|
||||
|
||||
Reference in New Issue
Block a user