oficina / memoria Public

Clone
git clone https://amadan.net/oficina/memoria

Plain git — no account needed to clone.

Download

Download this file

1package memoria
2
3import (
4 "context"
5
6 "amadan.net/oficina/memoria/internal/memoria/provider"
7)
8
9// Extractor is what §8.9 asks of a model: every postal address in the
10// sent passages, as pointers into them. provider.Client satisfies it; so
11// does a test's recorder, which is how gate 39 sees exactly what was sent.
12type Extractor interface {
13 ExtractAddresses(ctx context.Context, passages []string) ([]provider.Pointer, error)
14}
15
16// Answerer is what §8.11 asks of a model: an answer to the question from
17// the sent passages, as sentences citing them by index.
18type Answerer interface {
19 Answer(ctx context.Context, question string, passages []string) ([]provider.Sentence, error)
20}
21
22// WireModel switches the model layer on when the owner has asked for it,
23// and leaves it off otherwise.
24//
25// One call from main, with the logic here where it has tests — the
26// WireSiblings shape, for the reason AGENTS.md gives: a gate over main's
27// text can see that a call is spelled and never that it is reached, so
28// main should hold nothing worth getting wrong. The wiring gate lists
29// this call because its absence is silent: MEMORIA_AI=on would do nothing
30// at all, and nothing would say so.
31func WireModel(a *app, cfg Config) error {
32 if !cfg.AI {
33 return nil
34 }
35 c, err := provider.New(cfg.TensorXKey)
36 if err != nil {
37 return err
38 }
39 a.store.extractor = c
40 a.store.answerer = c
41 // Named, because decision 4 names the provider everywhere, and this
42 // is the line an operator reads to learn that content will leave.
43 // The key is not in it.
44 a.logger.Info("model layer on", "provider", provider.Name, "model", provider.Model)
45 return nil
46}
47
48// UseFakeModel wires a stand-in model, for tools/drive and tests.
49//
50// Named for what it is, and production never calls it —
51// TestProductionDoesNotUseTheTestConstructor fails if cmd/ does. It
52// matters more here than for the other seams: this one switches the
53// model layer on WITHOUT MEMORIA_AI, so in main it would bypass the
54// owner's opt-in (decision 4) — and, handed a real client, send content
55// the owner never agreed to send.
56func (a *app) UseFakeModel(e Extractor) {
57 a.store.extractor = e
58 if ans, ok := e.(Answerer); ok {
59 a.store.answerer = ans
60 }
61}
62
63// modelOn reports whether this instance may send passages to the model.
64// Every page's footer states the egress claim, and the claim depends on
65// this; one helper so no page can compute it differently.
66func (a *app) modelOn() bool { return a.store != nil && a.store.extractor != nil }
67