Add usage commands, a vendor-neutral usage format and a knowledge base
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
CREATE TABLE usage_commands (
|
||||
vendor TEXT PRIMARY KEY,
|
||||
command TEXT NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,43 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"g.fc.run/ai/byre/internal/api"
|
||||
)
|
||||
|
||||
func (s *Store) UsageCommands(ctx context.Context) (map[api.AgentSessionVendor]string, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT vendor, command FROM usage_commands`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
cmds := map[api.AgentSessionVendor]string{}
|
||||
for rows.Next() {
|
||||
vendor := ""
|
||||
cmd := ""
|
||||
err = rows.Scan(&vendor, &cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmds[api.AgentSessionVendor(vendor)] = cmd
|
||||
}
|
||||
return cmds, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) SetUsageCommands(ctx context.Context, actor string, cmds map[api.AgentSessionVendor]string) error {
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
for vendor, cmd := range cmds {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
INSERT INTO usage_commands (vendor, command) VALUES (?, ?)
|
||||
ON CONFLICT (vendor) DO UPDATE SET command = excluded.command
|
||||
`, string(vendor), cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return emit(api.Event{Kind: "admin.usage_commands", Actor: actor, Payload: map[string]any{}})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user