oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1// Package assist is the registry behind the Assistant's look, describe and
2// use tools: operations come from providers, and this package decides which
3// of them may run. It has no chat dependencies.
4package assist
5
6import (
7 "context"
8 "encoding/json"
9)
10
11// MaxResult is the most an operation result may carry back to the model,
12// inside the 64 KB tool frame.
13const MaxResult = 48 << 10
14
15// Operation is one thing a provider can do, in agent-access's shape.
16type Operation struct {
17 Name string `json:"name"`
18 Description string `json:"description"`
19 Scope string `json:"scope"`
20 ReadOnly bool `json:"read_only"`
21 Destructive bool `json:"destructive"`
22 Idempotent bool `json:"idempotent"`
23 External bool `json:"external"`
24 App string `json:"app"`
25 Input json.RawMessage `json:"input_schema"`
26 Output json.RawMessage `json:"output_schema"`
27 // Teams are the teams the model chooses among for the input's team,
28 // when its provider fills none in itself (the Oficina apps').
29 Teams []string `json:"teams,omitempty"`
30
31 Provider string `json:"-"`
32 // KeyField is where a client idempotency key goes in the input; empty
33 // when the operation takes none.
34 KeyField string `json:"-"`
35}
36
37// Provider lists and runs operations for a person.
38type Provider interface {
39 Name() string
40 List(ctx context.Context, person string) ([]Operation, error)
41 Invoke(ctx context.Context, person, operation string, input json.RawMessage, key string) (json.RawMessage, error)
42}
43
44// Failure is a refusal or error a provider or the registry reports with a
45// stable code the model can act on.
46type Failure struct{ Code, Message string }
47
48func (f Failure) Error() string {
49 if f.Message == "" {
50 return f.Code
51 }
52 return f.Code + ": " + f.Message
53}
54
55// Decide says whether an operation may run. It only ever narrows: reads run,
56// the team provider runs, anything destructive or external waits, and any
57// other write needs a client idempotency key so it can happen exactly once.
58func Decide(op Operation) (run bool, code string) {
59 switch {
60 case op.ReadOnly:
61 return true, ""
62 case op.Destructive || op.External:
63 return false, "not_yet"
64 case op.Provider == "team":
65 return true, ""
66 case op.KeyField == "":
67 return false, "write_not_supported"
68 }
69 return true, ""
70}
71