GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — harness/models.go at main · majorcontext/harness

Expand file tree

/

models.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
136 lines (125 loc) · 4.35 KB
/

models.go

Copy path

File metadata and controls

136 lines (125 loc) · 4.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package harness
import (
"context"
"fmt"
"github.com/majorcontext/harness/config"
"github.com/majorcontext/harness/internal/backend"
"github.com/majorcontext/harness/internal/modelref"
"github.com/majorcontext/harness/internal/session"
"github.com/majorcontext/harness/internal/turn"
"github.com/majorcontext/harness/protocol"
)
// ErrModelUnavailable reports a model that no configured provider serves.
var ErrModelUnavailable = backend.ErrUnavailable
// checkModel reports why model cannot start a session that allows the
// names. A backend that owns the loop runs only its built-in tools, the
// built-in tools of the WorkDir, and the tools that no model owns.
func (r *Runtime) checkModel(model string, names []string, session bool) error {
ref, err := modelref.ParseModelRef(model)
if err != nil {
return fmt.Errorf("%w: %w", ErrInvalidRequest, err)
}
be, err := r.models.Check(ref)
if err != nil {
return err
}
if err := r.checkShadowed(names); err != nil {
return err
}
caps := be.Capabilities(model)
if !caps.OwnsLoop {
return nil
}
for _, n := range caps.Tools {
if r.owns(n) {
return fmt.Errorf("%w: tool %q has the name of a built-in tool of %s", ErrInvalidRequest, n, model)
}
}
for _, n := range names {
if !r.knownIn(model, n, session) {
return fmt.Errorf("%w: %s has no tool %q", ErrInvalidRequest, model, n)
}
}
return nil
}
func (r *Runtime) checkEvaluator() error {
if r.evaluator == "" {
return fmt.Errorf("%w: a goal needs goal_evaluator_model", ErrInvalidRequest)
}
ref, err := modelref.ParseModelRef(r.evaluator)
if err != nil {
return fmt.Errorf("%w: %w", ErrInvalidRequest, err)
}
_, err = r.models.Check(ref)
return err
}
// changeModel reports why a session that allows the names cannot move to
// model to. A backend that owns its context reads the history of another
// provider through the history tool, so any two models may follow each other.
func (r *Runtime) changeModel(session bool) func(_, to string, names []string) error {
return func(_, to string, names []string) error { return r.checkModel(to, names, session) }
}
// checkShadowed fails when the session allows every tool and an embedder tool
// has the name of a built-in tool of the WorkDir.
func (r *Runtime) checkShadowed(names []string) error {
if names != nil {
return nil
}
if taken := r.shadowed(); len(taken) > 0 {
return fmt.Errorf("%w: tool %q has the name of a built-in tool, which the session allows; list the allowed tools to replace it", ErrInvalidRequest, taken[0])
}
return nil
}
// createdForOpen checks the effective allowlist before an Open fences the log.
func (r *Runtime) createdForOpen(ctx context.Context, id string, names *[]string) (protocol.SessionCreated, error) {
c, err := r.created(ctx, id)
if err != nil || len(r.shadowed()) == 0 {
return c, err
}
var tools []string
if names != nil {
tools = *names
} else {
state, err := session.Load(ctx, id, storeLog{r.store, id})
if err != nil {
return c, err
}
tools = state.AllowedTools()
}
return c, r.checkShadowed(tools)
}
// lineageOf returns the creation record of session id and its place in the
// session tree. On an error it releases own.
func (r *Runtime) lineageOf(ctx context.Context, own session.Ownership, id string, l launch) (c protocol.SessionCreated, root string, depth int, err error) {
if l.created != nil {
c = *l.created
} else if c, err = r.createdForOpen(ctx, id, l.allowedTools); err != nil {
session.Discard(own, id, r.log)
return c, "", 0, err
}
if root, depth, err = r.tree.Lineage(ctx, id, c.ParentID); err != nil {
session.Discard(own, id, r.log)
}
return c, root, depth, err
}
// modelRef resolves the optional model key ref of c through its aliases. An empty key gives no model.
func modelRef(c config.Config, ref string) string {
if ref == "" {
return ""
}
return c.ResolveModel(ref)
}
// checkOptions adds tools to the runtime and refuses a tool name that is empty,
// repeated, or reserved, and a bad plugin.
func (r *Runtime) checkOptions(tools []turn.Tool, opts Options) error {
for _, t := range tools {
if name := t.Spec().Name; name == "" || r.known("", name) && (!r.shadowable(name) || r.owns(name)) {
return fmt.Errorf("harness: tool name %q is empty, repeated, or reserved", name)
}
r.tools = append(r.tools, t)
}
if err := r.checkPlugins(opts.Config.Plugins, opts.Plugins); err != nil {
return err
}
return nil
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.