@pairz/team 1.0.0-rc.81 → 1.0.0-rc.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/WORDS.md +23 -2
- package/package.json +2 -2
- package/team/actions/agent.js +12 -4
- package/team/collections/agent.d.ts +70 -15
- package/team/collections/agent.js +29 -7
- package/team/shared/definition.d.ts +15 -0
- package/team/shared/definition.js +17 -1
- package/team/views/web/model-pick.d.ts +10 -1
- package/team/views/web/model-pick.js +4 -2
- package/team/views/web/model-picker.d.ts +31 -5
- package/team/views/web/model-picker.js +74 -30
- package/team/views/web/words.d.ts +1 -1
- package/team/views/web/words.js +7 -0
- package/tiers/actions/choose.d.ts +48 -1
- package/tiers/actions/choose.js +143 -57
- package/tiers/actions/model.js +14 -9
- package/tiers/collections/choice.d.ts +15 -8
- package/tiers/collections/choice.js +22 -12
- package/tiers/collections/template.d.ts +6 -1
- package/tiers/collections/template.js +8 -4
- package/tiers/contract.d.ts +2 -2
- package/tiers/mod.d.ts +17 -9
- package/tiers/mod.js +26 -12
- package/tiers/shared/plans.d.ts +31 -33
- package/tiers/shared/plans.js +39 -54
- package/tiers/shared/shown.d.ts +16 -3
- package/tiers/shared/shown.js +43 -15
- package/tiers/shared/tiers.d.ts +38 -5
- package/tiers/shared/tiers.js +29 -3
- package/tiers/views/web/composer.d.ts +2 -1
- package/tiers/views/web/composer.js +8 -2
- package/tiers/views/web/org.d.ts +46 -11
- package/tiers/views/web/org.js +144 -61
- package/tiers/views/web/say.d.ts +17 -2
- package/tiers/views/web/say.js +17 -2
- package/tiers/views/web/space.d.ts +2 -1
- package/tiers/views/web/space.js +8 -4
- package/tiers/views/web/style.d.ts +1 -1
- package/tiers/views/web/style.js +5 -0
- package/tiers/web.d.ts +6 -5
- package/tiers/web.js +9 -8
|
@@ -8,11 +8,43 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
8
8
|
* then one's models, newest first, with what each costs and can do. A provider
|
|
9
9
|
* without a key asks for one: the org's owners and admins add it here
|
|
10
10
|
* (`modelKey.set`), and it's never shown again; anyone else is told whom to ask.
|
|
11
|
+
*
|
|
12
|
+
* For a model people's turns run on their plans first (a tier's, `plans`),
|
|
13
|
+
* it offers every model the org can run, each saying how it's paid for the
|
|
14
|
+
* person looking: "Your Claude · $0" where a subscription of theirs runs it,
|
|
15
|
+
* "Credits" where a key covers it, and for a model only plans run, "Members
|
|
16
|
+
* without Claude fall back to the next model" (`members`: an org's tier, so
|
|
17
|
+
* it can be chosen) or "Connect Claude to use" (`mine`: their own).
|
|
11
18
|
*/
|
|
12
19
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
13
20
|
import { createPortal } from "react-dom";
|
|
14
21
|
import { Badge, Button, Dialog, formatNumber, Icon, IconButton, Input, message, Notice, Skeleton, } from "pairz/web";
|
|
22
|
+
import { formatList } from "pairz/web/words";
|
|
15
23
|
import { say } from "./words.js";
|
|
24
|
+
/** Whether a model can be chosen: a key covers it, or a plan runs it that's theirs, or members'. */
|
|
25
|
+
export const choosable = (model, plans) => model.ready || (!!plans && (!!model.yours || (plans === "members" && !!model.plans?.length)));
|
|
26
|
+
/** Whether a provider has models to choose now, as `choosable` says of one. */
|
|
27
|
+
const reachable = (provider, plans) => provider.ready ||
|
|
28
|
+
(!!plans && (!!provider.yours?.length || (plans === "members" && !!provider.plans?.length)));
|
|
29
|
+
/**
|
|
30
|
+
* How a model is paid for, for the person looking, where turns run on plans
|
|
31
|
+
* first: their subscription ("Your Claude · $0"), else credits, at its price,
|
|
32
|
+
* else, for a model only plans run, who falls back or what to connect.
|
|
33
|
+
*/
|
|
34
|
+
export function paidSaid(model, plans) {
|
|
35
|
+
if (model.yours)
|
|
36
|
+
return say("paidYours", { plan: model.yours });
|
|
37
|
+
if (model.ready) {
|
|
38
|
+
const cost = priced(model);
|
|
39
|
+
return model.ownKey ? cost : cost ? say("paidCredits", { price: cost }) : say("credits");
|
|
40
|
+
}
|
|
41
|
+
if (!model.plans?.length)
|
|
42
|
+
return undefined;
|
|
43
|
+
const names = formatList(model.plans, "disjunction");
|
|
44
|
+
return plans === "members"
|
|
45
|
+
? say("paidFallBack", { plans: names })
|
|
46
|
+
: say("paidConnect", { plans: names });
|
|
47
|
+
}
|
|
16
48
|
/** How long after typing it searches. */
|
|
17
49
|
const TYPING_MS = 180;
|
|
18
50
|
/** Tokens, shortly: `200K`, `1M`. */
|
|
@@ -60,7 +92,7 @@ function abilities(model) {
|
|
|
60
92
|
...(model.reasons ? [say("reasoning")] : []),
|
|
61
93
|
];
|
|
62
94
|
}
|
|
63
|
-
export function ModelPicker({ value, onChange, call, disabled, id, look = "field", label }) {
|
|
95
|
+
export function ModelPicker({ value, onChange, call, disabled, id, look = "field", label, plans }) {
|
|
64
96
|
const [open, setOpen] = useState(false);
|
|
65
97
|
const [chosen, setChosen] = useState();
|
|
66
98
|
// What's chosen, by name, for the field; a link leaves that to the line it's on.
|
|
@@ -69,16 +101,20 @@ export function ModelPicker({ value, onChange, call, disabled, id, look = "field
|
|
|
69
101
|
return setChosen(undefined);
|
|
70
102
|
call("models.offered", {
|
|
71
103
|
model: value,
|
|
104
|
+
...(plans ? { plans: true } : {}),
|
|
72
105
|
}).then(setChosen, () => setChosen(undefined));
|
|
73
|
-
}, [value, call, look]);
|
|
106
|
+
}, [value, call, look, plans]);
|
|
74
107
|
useEffect(load, [load]);
|
|
75
|
-
// Known and not ready: nothing can reach it until its key is added.
|
|
76
|
-
const stuck =
|
|
108
|
+
// Known and not ready: nothing can reach it until its key is added (or, on plans, theirs).
|
|
109
|
+
const stuck = plans
|
|
110
|
+
? !!chosen?.model && !choosable(chosen.model, plans)
|
|
111
|
+
: chosen?.provider && !chosen.provider.ready;
|
|
112
|
+
const line = chosen?.model && (plans ? paidSaid(chosen.model, plans) : priced(chosen.model));
|
|
77
113
|
const dialog = open
|
|
78
114
|
? createPortal(_jsx(Dialog, { open: true, onClose: () => {
|
|
79
115
|
setOpen(false);
|
|
80
116
|
load();
|
|
81
|
-
}, title: say("chooseModel"), className: "model-dialog", children: _jsx(Choosing, { value: value, call: call, onChoose: (model) => {
|
|
117
|
+
}, title: say("chooseModel"), className: "model-dialog", children: _jsx(Choosing, { value: value, call: call, plans: plans, onChoose: (model) => {
|
|
82
118
|
onChange(model);
|
|
83
119
|
setOpen(false);
|
|
84
120
|
} }) }), document.body)
|
|
@@ -86,62 +122,69 @@ export function ModelPicker({ value, onChange, call, disabled, id, look = "field
|
|
|
86
122
|
if (look === "link") {
|
|
87
123
|
return (_jsxs(_Fragment, { children: [_jsx(Button, { id: id, variant: "link", size: "sm", className: "model-change", disabled: disabled, "aria-haspopup": "dialog", onClick: () => setOpen(true), children: label ?? say("change") }), dialog] }));
|
|
88
124
|
}
|
|
89
|
-
return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", id: id, className: "model-chosen", disabled: disabled, "aria-haspopup": "dialog", onClick: () => setOpen(true), children: [_jsxs("span", { className: "model-chosen-text", children: [_jsx("b", { children: chosen?.model?.name ?? (value || say("chooseModel")) }), _jsxs("span", { children: [chosen?.provider?.name,
|
|
125
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", id: id, className: "model-chosen", disabled: disabled, "aria-haspopup": "dialog", onClick: () => setOpen(true), children: [_jsxs("span", { className: "model-chosen-text", children: [_jsx("b", { children: chosen?.model?.name ?? (value || say("chooseModel")) }), _jsxs("span", { children: [chosen?.model?.from ?? chosen?.provider?.name, line ? ` · ${line}` : ""] })] }), stuck && !chosen?.model?.plans?.length
|
|
126
|
+
? _jsx(Badge, { tone: "warning", children: say("needsKey") })
|
|
127
|
+
: null, _jsx(Icon, { name: "selector", size: 16 })] }), dialog] }));
|
|
90
128
|
}
|
|
91
129
|
/** What's in the dialog: the search, then what it found, the providers, or one provider. */
|
|
92
|
-
function Choosing({ value, call, onChoose }) {
|
|
130
|
+
function Choosing({ value, call, plans, onChoose }) {
|
|
93
131
|
const [listing, setListing] = useState();
|
|
94
132
|
const [typed, setTyped] = useState("");
|
|
95
133
|
const [found, setFound] = useState();
|
|
96
134
|
const [at, setAt] = useState();
|
|
97
135
|
const [error, setError] = useState();
|
|
136
|
+
const asked = plans ? { plans: true } : {};
|
|
98
137
|
const list = useCallback(() => {
|
|
99
|
-
call("models.offered", {}).then(setListing, (e) => setError(message(e)));
|
|
100
|
-
}, [call]);
|
|
138
|
+
call("models.offered", { ...asked }).then(setListing, (e) => setError(message(e)));
|
|
139
|
+
}, [call, plans]);
|
|
101
140
|
useEffect(list, [list]);
|
|
102
141
|
// The last search asked is the one that shows.
|
|
103
|
-
const
|
|
142
|
+
const last = useRef(0);
|
|
104
143
|
useEffect(() => {
|
|
105
144
|
const search = typed.trim();
|
|
106
|
-
const mine = ++
|
|
145
|
+
const mine = ++last.current;
|
|
107
146
|
if (!search)
|
|
108
147
|
return setFound(undefined);
|
|
109
148
|
const timer = setTimeout(() => {
|
|
110
|
-
call("models.offered", { search }).then((answer) => mine ===
|
|
149
|
+
call("models.offered", { search, ...asked }).then((answer) => mine === last.current && setFound(answer), (e) => mine === last.current && setError(message(e)));
|
|
111
150
|
}, TYPING_MS);
|
|
112
151
|
return () => clearTimeout(timer);
|
|
113
|
-
}, [typed, call]);
|
|
152
|
+
}, [typed, call, plans]);
|
|
114
153
|
if (at) {
|
|
115
|
-
return (_jsx(ProviderModels, { id: at, value: value, call: call, may: !!listing?.set, onBack: () => {
|
|
154
|
+
return (_jsx(ProviderModels, { id: at, value: value, call: call, plans: plans, may: !!listing?.set, onBack: () => {
|
|
116
155
|
setAt(undefined);
|
|
117
156
|
list();
|
|
118
157
|
}, onChoose: onChoose }));
|
|
119
158
|
}
|
|
120
159
|
return (_jsxs("div", { className: "model-choose", children: [_jsx(Input, { icon: "search", placeholder: say("searchModels"), "aria-label": say("searchModels"), value: typed, autoFocus: true, onChange: (event) => setTyped(event.target.value) }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, typed.trim()
|
|
121
|
-
? _jsx(Results, { found: found, value: value, onProvider: setAt, onChoose: onChoose })
|
|
122
|
-
: _jsx(Providers, { listing: listing, onProvider: setAt })] }));
|
|
160
|
+
? (_jsx(Results, { found: found, value: value, plans: plans, onProvider: setAt, onChoose: onChoose }))
|
|
161
|
+
: _jsx(Providers, { listing: listing, plans: plans, onProvider: setAt })] }));
|
|
123
162
|
}
|
|
124
163
|
const Loading = () => (_jsx("div", { className: "model-list", "aria-busy": "true", children: [0, 1, 2, 3].map((n) => _jsx(Skeleton, { height: 46 }, n)) }));
|
|
125
164
|
function ProviderRow({ provider, onOpen }) {
|
|
126
|
-
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "model-row", onClick: onOpen, children: [_jsxs("span", { className: "model-row-text", children: [_jsx("b", { children: provider.name }), _jsxs("span", { children: [say("providerModels", { count: provider.models }), provider.note ? ` · ${provider.note}` : ""] })] }), provider.hint
|
|
165
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "model-row", onClick: onOpen, children: [_jsxs("span", { className: "model-row-text", children: [_jsx("b", { children: provider.name }), _jsxs("span", { children: [say("providerModels", { count: provider.models }), provider.note ? ` · ${provider.note}` : ""] })] }), provider.hint
|
|
166
|
+
? _jsx(Badge, { tone: "primary", children: say("yourKey") })
|
|
167
|
+
: provider.yours?.length
|
|
168
|
+
? _jsx(Badge, { tone: "primary", children: say("yourPlan", { plan: provider.yours[0] }) })
|
|
169
|
+
: null, _jsx(Icon, { name: "chevron", size: 15 })] }) }));
|
|
127
170
|
}
|
|
128
|
-
/** The providers: those that can be used now, then those that take a key. */
|
|
129
|
-
export function Providers({ listing, onProvider }) {
|
|
171
|
+
/** The providers: those that can be used now (a key, or a plan), then those that take a key. */
|
|
172
|
+
export function Providers({ listing, plans, onProvider }) {
|
|
130
173
|
if (!listing)
|
|
131
174
|
return _jsx(Loading, {});
|
|
132
|
-
const ready = listing.providers.filter((p) => p
|
|
133
|
-
const others = listing.providers.filter((p) => !p
|
|
175
|
+
const ready = listing.providers.filter((p) => reachable(p, plans));
|
|
176
|
+
const others = listing.providers.filter((p) => !reachable(p, plans));
|
|
134
177
|
return (_jsxs("div", { className: "model-groups", children: [ready.length
|
|
135
178
|
? (_jsxs("section", { children: [_jsx("h3", { className: "model-group", children: say("readyToUse") }), _jsx("ul", { className: "model-list", children: ready.map((p) => (_jsx(ProviderRow, { provider: p, onOpen: () => onProvider(p.id) }, p.id))) })] }))
|
|
136
179
|
: null, others.length
|
|
137
180
|
? (_jsxs("section", { children: [_jsx("h3", { className: "model-group", children: say("withOwnKey") }), _jsx("ul", { className: "model-list", children: others.map((p) => (_jsx(ProviderRow, { provider: p, onOpen: () => onProvider(p.id) }, p.id))) })] }))
|
|
138
181
|
: null] }));
|
|
139
182
|
}
|
|
140
|
-
export function ModelRow({ model, value, withProvider, onChoose }) {
|
|
141
|
-
const cost = priced(model);
|
|
142
|
-
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "model-row model-row-model", disabled: !model
|
|
183
|
+
export function ModelRow({ model, value, withProvider, plans, onChoose }) {
|
|
184
|
+
const cost = plans ? paidSaid(model, plans) : priced(model);
|
|
185
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "model-row model-row-model", disabled: !choosable(model, plans), "aria-current": model.id === value || undefined, onClick: onChoose, children: [_jsxs("span", { className: "model-row-text", children: [_jsx("b", { children: model.name }), _jsx("span", { children: [withProvider, ...abilities(model)].filter(Boolean).join(" · ") }), cost ? _jsx("span", { children: cost }) : null] }), model.id === value ? _jsx(Icon, { name: "check", size: 16 }) : null] }) }));
|
|
143
186
|
}
|
|
144
|
-
export function Results({ found, value, onProvider, onChoose }) {
|
|
187
|
+
export function Results({ found, value, plans, onProvider, onChoose }) {
|
|
145
188
|
if (!found)
|
|
146
189
|
return _jsx(Loading, {});
|
|
147
190
|
if (!found.providers.length && !found.models.length) {
|
|
@@ -150,26 +193,27 @@ export function Results({ found, value, onProvider, onChoose }) {
|
|
|
150
193
|
return (_jsxs("div", { className: "model-groups", children: [found.providers.length
|
|
151
194
|
? (_jsxs("section", { children: [_jsx("h3", { className: "model-group", children: say("providers") }), _jsx("ul", { className: "model-list", children: found.providers.map((p) => (_jsx(ProviderRow, { provider: p, onOpen: () => onProvider(p.id) }, p.id))) })] }))
|
|
152
195
|
: null, found.models.length
|
|
153
|
-
? (_jsxs("section", { children: [_jsx("h3", { className: "model-group", children: say("models") }), _jsx("ul", { className: "model-list", children: found.models.map((m) => m.
|
|
154
|
-
? (_jsx(ModelRow, { model: m, value: value, withProvider: m.from, onChoose: () => onChoose(m.id) }, m.id))
|
|
196
|
+
? (_jsxs("section", { children: [_jsx("h3", { className: "model-group", children: say("models") }), _jsx("ul", { className: "model-list", children: found.models.map((m) => choosable(m, plans) || m.plans?.length
|
|
197
|
+
? (_jsx(ModelRow, { model: m, value: value, withProvider: m.from, plans: plans, onChoose: () => onChoose(m.id) }, m.id))
|
|
155
198
|
: (_jsx("li", { children: _jsxs("button", { type: "button", className: "model-row", onClick: () => onProvider(m.provider), children: [_jsxs("span", { className: "model-row-text", children: [_jsx("b", { children: m.name }), _jsx("span", { children: m.from })] }), _jsx(Badge, { children: say("needsKey") })] }) }, m.id))) })] }))
|
|
156
199
|
: null] }));
|
|
157
200
|
}
|
|
158
201
|
/** One provider: its key, if it takes one, and its models. */
|
|
159
|
-
function ProviderModels({ id, value, call, may, onBack, onChoose }) {
|
|
202
|
+
function ProviderModels({ id, value, call, plans, may, onBack, onChoose }) {
|
|
160
203
|
const [shown, setShown] = useState();
|
|
161
204
|
const [error, setError] = useState();
|
|
162
205
|
const load = useCallback(() => {
|
|
163
206
|
call("models.offered", {
|
|
164
207
|
provider: id,
|
|
208
|
+
...(plans ? { plans: true } : {}),
|
|
165
209
|
}).then(setShown, (e) => setError(message(e)));
|
|
166
|
-
}, [id, call]);
|
|
210
|
+
}, [id, call, plans]);
|
|
167
211
|
useEffect(load, [load]);
|
|
168
212
|
const provider = shown?.provider;
|
|
169
213
|
return (_jsxs("div", { className: "model-choose", children: [_jsxs("div", { className: "model-provider-head", children: [_jsx(IconButton, { icon: "chevron-left", label: say("allProviders"), size: "sm", onClick: onBack }), _jsx("h3", { children: provider?.name ?? id })] }), provider?.note ? _jsx("p", { className: "model-provider-note", children: provider.note }) : null, error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, provider?.keyed
|
|
170
214
|
? _jsx(ProviderKey, { provider: provider, may: may, call: call, onChange: load })
|
|
171
215
|
: null, shown
|
|
172
|
-
? (_jsx("ul", { className: "model-list", children: shown.models.map((m) => (_jsx(ModelRow, { model: m, value: value, onChoose: () => onChoose(m.id) }, m.id))) }))
|
|
216
|
+
? (_jsx("ul", { className: "model-list", children: shown.models.map((m) => (_jsx(ModelRow, { model: m, value: value, plans: plans, onChoose: () => onChoose(m.id) }, m.id))) }))
|
|
173
217
|
: _jsx(Loading, {})] }));
|
|
174
218
|
}
|
|
175
219
|
/** The org's key for a provider: added, replaced or removed by those who run it. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Every word Team's web front end shows, to be changed by the app (`team.<key>`). */
|
|
2
2
|
import { type Phrase } from "pairz/web/words";
|
|
3
|
-
export declare const say: import("pairz/web/words").Say<"instructions" | "model" | "effort" | "tools" | "replace" | "cancel" | "change" | "listJoin" | "listEnd" | "personalSpace" | "noSuchAgentTitle" | "noSuchAgent" | "noSuchAgentBody" | "goHome" | "partOfApp" | "madeIn" | "madeElsewhere" | "answersNewChatsHere" | "askAgent" | "edit" | "editAgent" | "moreMenu" | "makeAnswerIn" | "addToSpaceMenu" | "startFromIt" | "deleteMenu" | "addToTitle" | "addToNote" | "newLikeTitle" | "newLikeNote" | "newAgentIn" | "startingFrom" | "appAgentNotice" | "startFromShort" | "managersChangeIt" | "managersChangeItElsewhere" | "worksIn" | "addToSpace" | "answersNewChats" | "roleViewer" | "roleEditor" | "worksNowhere" | "modelAndTools" | "thinks" | "toolsLabel" | "noTools" | "showFewer" | "showAll" | "modelsThenJoin" | "changeAgent" | "keepsHandle" | "saveChanges" | "deleteTitle" | "deleteButton" | "deleteLeavesBold" | "deleteLeavesNamed" | "deleteLeaves" | "deleteGoneBold" | "deleteGone" | "deleteChatsBold" | "deleteChats" | "findSpace" | "spacesYouManage" | "justYou" | "keywordPersonal" | "deleteStepNote" | "deleteStepKeep" | "fieldName" | "calledIn" | "nameHint" | "namePlaceholder" | "emoji" | "noEmoji" | "anotherEmoji" | "otherEmoji" | "fieldDoes" | "doesHint" | "doesPlaceholder" | "modelHint" | "rewriteForMe" | "writeForMe" | "sayNameFirst" | "youArePlaceholder" | "youAreDefaultName" | "writingFor" | "draftNote" | "undo" | "instructionsHint" | "instructionsEmptyHint" | "toolsOf" | "toolsChooseDone" | "toolsChoose" | "toolsAll" | "toolsNone" | "toolsMore" | "newAgentForm" | "agentsYouKnow" | "startFrom" | "startBlank" | "worksInAs" | "belongsHint" | "createNamed" | "createAgent" | "worksNow" | "askHandle" | "readsOnly" | "makeAnswer" | "openPage" | "makeAnother" | "notYourSpace" | "archivedSpace" | "managersAdd" | "addAnAgentTitle" | "addAnAgentNote" | "oneOfApps" | "madeInOther" | "findAgent" | "findAgentKnown" | "knownIntro" | "addsAs" | "createNewAgent" | "createNewAgentBody" | "addAgentTo" | "
|
|
3
|
+
export declare const say: import("pairz/web/words").Say<"add" | "remove" | "instructions" | "model" | "effort" | "tools" | "replace" | "cancel" | "change" | "listJoin" | "listEnd" | "personalSpace" | "noSuchAgentTitle" | "noSuchAgent" | "noSuchAgentBody" | "goHome" | "partOfApp" | "madeIn" | "madeElsewhere" | "answersNewChatsHere" | "askAgent" | "edit" | "editAgent" | "moreMenu" | "makeAnswerIn" | "addToSpaceMenu" | "startFromIt" | "deleteMenu" | "addToTitle" | "addToNote" | "newLikeTitle" | "newLikeNote" | "newAgentIn" | "startingFrom" | "appAgentNotice" | "startFromShort" | "managersChangeIt" | "managersChangeItElsewhere" | "worksIn" | "addToSpace" | "answersNewChats" | "roleViewer" | "roleEditor" | "worksNowhere" | "modelAndTools" | "thinks" | "toolsLabel" | "noTools" | "showFewer" | "showAll" | "modelsThenJoin" | "changeAgent" | "keepsHandle" | "saveChanges" | "deleteTitle" | "deleteButton" | "deleteLeavesBold" | "deleteLeavesNamed" | "deleteLeaves" | "deleteGoneBold" | "deleteGone" | "deleteChatsBold" | "deleteChats" | "findSpace" | "spacesYouManage" | "justYou" | "keywordPersonal" | "deleteStepNote" | "deleteStepKeep" | "fieldName" | "calledIn" | "nameHint" | "namePlaceholder" | "emoji" | "noEmoji" | "anotherEmoji" | "otherEmoji" | "fieldDoes" | "doesHint" | "doesPlaceholder" | "modelHint" | "rewriteForMe" | "writeForMe" | "sayNameFirst" | "youArePlaceholder" | "youAreDefaultName" | "writingFor" | "draftNote" | "undo" | "instructionsHint" | "instructionsEmptyHint" | "toolsOf" | "toolsChooseDone" | "toolsChoose" | "toolsAll" | "toolsNone" | "toolsMore" | "newAgentForm" | "agentsYouKnow" | "startFrom" | "startBlank" | "worksInAs" | "belongsHint" | "createNamed" | "createAgent" | "worksNow" | "askHandle" | "readsOnly" | "makeAnswer" | "openPage" | "makeAnother" | "notYourSpace" | "archivedSpace" | "managersAdd" | "addAnAgentTitle" | "addAnAgentNote" | "oneOfApps" | "madeInOther" | "findAgent" | "findAgentKnown" | "knownIntro" | "addsAs" | "createNewAgent" | "createNewAgentBody" | "addAgentTo" | "noneCalled" | "allWorkHere" | "worksNowNames" | "paletteThisAgent" | "paletteThisSpace" | "paletteAgents" | "paletteCreate" | "makeNamedAnswerIn" | "makeNamedAnswer" | "keywordDefault" | "keywordAnswer" | "keywordNewChats" | "addNamedTo" | "addNamedNote" | "keywordMember" | "keywordJoin" | "keywordWork" | "editNamed" | "keywordChange" | "keywordInstructions" | "keywordRename" | "startNewFrom" | "keywordCopy" | "keywordLike" | "keywordCreate" | "addAnAgentTo" | "keywordInvite" | "keywordAgent" | "worksHere" | "newAgent" | "newAgentInHere" | "keywordMake" | "newAgentInStep" | "newAgentInNote" | "chooseModel" | "needsKey" | "yourKey" | "providerModels" | "searchModels" | "readyToUse" | "withOwnKey" | "providers" | "models" | "nothingMatches" | "allProviders" | "noKeyForProvider" | "apiKeyLabel" | "pasteIt" | "save" | "keyNote" | "orgKey" | "usesAppKey" | "useOwnKey" | "noCreditsUsed" | "priceLine" | "priceOwnKey" | "paidYours" | "paidCredits" | "credits" | "paidFallBack" | "paidConnect" | "yourPlan" | "contextSize" | "mediaImage" | "mediaPdf" | "mediaAudio" | "mediaVideo" | "reasoning" | "describeHint" | "describePlaceholder" | "fillMyself" | "draftIt" | "drafting" | "draftingWait" | "kindLabel" | "kindHint" | "kindLike" | "orgForm" | "orgJoins" | "back" | "addToTeamNamed" | "addToTeam" | "removeFromTeamMenu" | "changedForOrg" | "orgsTeam" | "tierModel" | "tierModelPlace" | "removeTeamTitle" | "removeButton" | "teamLeaves" | "teamLeavesBold" | "teamSaidStays" | "teamAddBack" | "teamDeleted">;
|
|
4
4
|
/** Every word of team's front end, by area (WORDS.md lists them). */
|
|
5
5
|
export declare const PHRASES: Record<string, Record<string, Phrase>>;
|
package/team/views/web/words.js
CHANGED
|
@@ -199,6 +199,13 @@ const team = {
|
|
|
199
199
|
noCreditsUsed: "No credits used",
|
|
200
200
|
priceLine: "{input} in · {output} out per 1M tokens",
|
|
201
201
|
priceOwnKey: "No credits used: your key, at {price}",
|
|
202
|
+
// How a model is paid for, where turns run on people's plans first
|
|
203
|
+
paidYours: "Your {plan} · $0",
|
|
204
|
+
paidCredits: "Credits · {price}",
|
|
205
|
+
credits: "Credits",
|
|
206
|
+
paidFallBack: "Members without {plans} fall back to the next model",
|
|
207
|
+
paidConnect: "Connect {plans} to use",
|
|
208
|
+
yourPlan: "Your {plan}",
|
|
202
209
|
contextSize: "{size} context",
|
|
203
210
|
mediaImage: "Images",
|
|
204
211
|
mediaPdf: "PDFs",
|
|
@@ -1,6 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choosing tiers, and the org's own: all in person.
|
|
3
|
+
*
|
|
4
|
+
* - `tiers.choose` `{ tier, space?, thread?, mine? }`: the tier for the org
|
|
5
|
+
* (its owners and admins), a space (its managers), a conversation (anyone
|
|
6
|
+
* in it) or the person's own default for new chats (`mine`); null: the one
|
|
7
|
+
* above. Those who don't run the org can't choose a tier over its `cap`;
|
|
8
|
+
* where the org uses only its default (`fixed`), nobody chooses below it.
|
|
9
|
+
* - `tiers.cap` `{ tier?, fixed? }`: what the org's members may use, by its
|
|
10
|
+
* owners and admins: every tier (`tier: null`), tiers up to one (`tier`),
|
|
11
|
+
* or only the org's default (`fixed: true`).
|
|
12
|
+
* - `tiers.plansFirst` `{ on }`: whether members' subscriptions are used
|
|
13
|
+
* whenever possible, by the org's owners and admins. Off (the default), a
|
|
14
|
+
* turn runs the tier's models in order, each on the member's plans that
|
|
15
|
+
* run it, then on credits. On, every model on their plans before any on
|
|
16
|
+
* credits, then the tier's `fallbacks` on their plans only.
|
|
17
|
+
* - `tiers.order` `{ tiers }`: the org's tiers in the order it wants them,
|
|
18
|
+
* lowest first, each once: where a cap stops.
|
|
19
|
+
* - `tiers.save` `{ tier, title?, description?, kinds?, fallbacks?, from? }`:
|
|
20
|
+
* an org's tier, by its owners and admins: its version of one of the
|
|
21
|
+
* app's, or a new one (`title`, its chains copied from `from`, else the
|
|
22
|
+
* tier in force). `kinds`: chains by kind of work (a list of models, tried
|
|
23
|
+
* in order; null: back to the app's there), each checked as an agent's
|
|
24
|
+
* model is, and each given the `maxTokens` and `effort` of the chain it
|
|
25
|
+
* replaces, where it takes it. `fallbacks`: the models tried on members'
|
|
26
|
+
* plans after any chain (null: back to the app's), each one a plan of the
|
|
27
|
+
* app's runs; one it had keeps its settings.
|
|
28
|
+
* - `tiers.remove` `{ tier }`: takes one of the app's away, or deletes one
|
|
29
|
+
* the org made; not the last. Wherever it was chosen, what's above applies.
|
|
30
|
+
* - `tiers.restore` `{ tier }`: one of the app's back as the app has it.
|
|
31
|
+
* - `tiers.kind` `{ kind?, title, base }`: a kind of work of the org's own,
|
|
32
|
+
* starting from one of the app's (its chain in every tier, until changed).
|
|
33
|
+
*
|
|
34
|
+
* A change applies from each conversation's next reply.
|
|
35
|
+
*/
|
|
36
|
+
import { type Resources } from "pairz";
|
|
37
|
+
import { type ModelRef } from "pairz/plugins/models/contract";
|
|
1
38
|
export declare const chooseAction: import("pairz").ActionDef;
|
|
2
39
|
export declare const capAction: import("pairz").ActionDef;
|
|
3
|
-
export declare const
|
|
40
|
+
export declare const plansFirstAction: import("pairz").ActionDef;
|
|
41
|
+
/**
|
|
42
|
+
* Throws unless a plan of the app's runs `fallback` (a tier's fallbacks run
|
|
43
|
+
* on members' plans only), at the settings it's given. An app without plans
|
|
44
|
+
* never runs one: nothing to check.
|
|
45
|
+
*/
|
|
46
|
+
export declare function checkFallback(ctx: {
|
|
47
|
+
resources: Resources;
|
|
48
|
+
call<R>(action: string, input?: unknown): Promise<R>;
|
|
49
|
+
}, fallback: ModelRef): Promise<void>;
|
|
50
|
+
export declare const orderAction: import("pairz").ActionDef;
|
|
4
51
|
export declare const saveAction: import("pairz").ActionDef;
|
|
5
52
|
export declare const removeAction: import("pairz").ActionDef;
|
|
6
53
|
export declare const restoreAction: import("pairz").ActionDef;
|
package/tiers/actions/choose.js
CHANGED
|
@@ -4,57 +4,73 @@
|
|
|
4
4
|
* - `tiers.choose` `{ tier, space?, thread?, mine? }`: the tier for the org
|
|
5
5
|
* (its owners and admins), a space (its managers), a conversation (anyone
|
|
6
6
|
* in it) or the person's own default for new chats (`mine`); null: the one
|
|
7
|
-
* above. Those who don't run the org can't choose a tier over its `cap
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* above. Those who don't run the org can't choose a tier over its `cap`;
|
|
8
|
+
* where the org uses only its default (`fixed`), nobody chooses below it.
|
|
9
|
+
* - `tiers.cap` `{ tier?, fixed? }`: what the org's members may use, by its
|
|
10
|
+
* owners and admins: every tier (`tier: null`), tiers up to one (`tier`),
|
|
11
|
+
* or only the org's default (`fixed: true`).
|
|
12
|
+
* - `tiers.plansFirst` `{ on }`: whether members' subscriptions are used
|
|
13
|
+
* whenever possible, by the org's owners and admins. Off (the default), a
|
|
14
|
+
* turn runs the tier's models in order, each on the member's plans that
|
|
15
|
+
* run it, then on credits. On, every model on their plans before any on
|
|
16
|
+
* credits, then the tier's `fallbacks` on their plans only.
|
|
17
|
+
* - `tiers.order` `{ tiers }`: the org's tiers in the order it wants them,
|
|
18
|
+
* lowest first, each once: where a cap stops.
|
|
19
|
+
* - `tiers.save` `{ tier, title?, description?, kinds?, fallbacks?, from? }`:
|
|
20
|
+
* an org's tier, by its owners and admins: its version of one of the
|
|
21
|
+
* app's, or a new one (`title`, its chains copied from `from`, else the
|
|
22
|
+
* tier in force). `kinds`: chains by kind of work (a list of models, tried
|
|
23
|
+
* in order; null: back to the app's there), each checked as an agent's
|
|
24
|
+
* model is, and each given the `maxTokens` and `effort` of the chain it
|
|
25
|
+
* replaces, where it takes it. `fallbacks`: the models tried on members'
|
|
26
|
+
* plans after any chain (null: back to the app's), each one a plan of the
|
|
27
|
+
* app's runs; one it had keeps its settings.
|
|
17
28
|
* - `tiers.remove` `{ tier }`: takes one of the app's away, or deletes one
|
|
18
29
|
* the org made; not the last. Wherever it was chosen, what's above applies.
|
|
19
30
|
* - `tiers.restore` `{ tier }`: one of the app's back as the app has it.
|
|
20
31
|
* - `tiers.kind` `{ kind?, title, base }`: a kind of work of the org's own,
|
|
21
32
|
* starting from one of the app's (its chain in every tier, until changed).
|
|
22
|
-
* - `tiers.harnesses` `{ harnesses }`: the order the person's plans run
|
|
23
|
-
* their agents' models in (the app's plans, by provider; the rest after,
|
|
24
|
-
* in the app's order); null: the app's. Kept on their own choice, beside
|
|
25
|
-
* their tier for new chats.
|
|
26
33
|
*
|
|
27
34
|
* A change applies from each conversation's next reply.
|
|
28
35
|
*/
|
|
29
36
|
import { defineAction, failure, inPerson, invalid } from "pairz";
|
|
30
37
|
import { must, ORG } from "pairz/plugins/access/contract";
|
|
38
|
+
import { plansInOrder } from "pairz/plugins/models/contract";
|
|
31
39
|
import { harnessesOf } from "../shared/plans.js";
|
|
32
40
|
import { orgTiersOf } from "../shared/shown.js";
|
|
33
|
-
import { aboveCap, appKindsOf, appTiersOf, entryOf, ORG_CHOICE, personChoice, settled, spaceChoice, threadChoice, } from "../shared/tiers.js";
|
|
41
|
+
import { aboveCap, appKindsOf, appTiersOf, entryOf, ORG_CHOICE, personChoice, primaryOf, settled, spaceChoice, threadChoice, } from "../shared/tiers.js";
|
|
34
42
|
/** Throws unless the caller runs the org. */
|
|
35
43
|
const runsOrg = (ctx, what) => must(ctx, "manage", ORG, `Only the org's owners and admins ${what}.`);
|
|
36
44
|
/** Whether the caller runs the org, without throwing. */
|
|
37
45
|
const running = (ctx) => runsOrg(ctx, "do that").then(() => true, () => false);
|
|
38
46
|
const choices = (ctx) => ctx.as().db.collection("modelChoice");
|
|
39
47
|
const templates = (ctx) => ctx.as().db.collection("tierTemplate");
|
|
40
|
-
/** Keeps a level's choice, or deletes it once it holds nothing (no tier,
|
|
48
|
+
/** Keeps a level's choice, or deletes it once it holds nothing (no tier, nor what members use). */
|
|
41
49
|
async function keep(ctx, had, next) {
|
|
42
|
-
if (!next.tier && !next.cap && !next.
|
|
50
|
+
if (!next.tier && !next.cap && !next.fixed && !next.plansFirst) {
|
|
43
51
|
if (had)
|
|
44
52
|
await choices(ctx).deleteOne({ _id: next._id });
|
|
45
53
|
return;
|
|
46
54
|
}
|
|
47
55
|
await choices(ctx).replaceOne({ _id: next._id }, next, { upsert: true });
|
|
48
56
|
}
|
|
49
|
-
/**
|
|
57
|
+
/** A level's choice as it's kept now: a person's old order of their plans goes. */
|
|
58
|
+
async function choiceOf(ctx, id) {
|
|
59
|
+
const found = await choices(ctx).findOne({ _id: id });
|
|
60
|
+
if (!found)
|
|
61
|
+
return null;
|
|
62
|
+
const { harnesses: _, ...kept } = found;
|
|
63
|
+
return kept;
|
|
64
|
+
}
|
|
65
|
+
/** Sets or clears one level's tier, keeping what else it holds (the org's cap). */
|
|
50
66
|
async function setTier(ctx, id, tier, more) {
|
|
51
|
-
const
|
|
52
|
-
const next = { ...
|
|
67
|
+
const before = await choiceOf(ctx, id);
|
|
68
|
+
const next = { ...before, ...more, _id: id, at: new Date().toISOString() };
|
|
53
69
|
if (tier)
|
|
54
70
|
next.tier = tier;
|
|
55
71
|
else
|
|
56
72
|
delete next.tier;
|
|
57
|
-
await keep(ctx,
|
|
73
|
+
await keep(ctx, before, next);
|
|
58
74
|
}
|
|
59
75
|
export const chooseAction = defineAction({
|
|
60
76
|
description: "Chooses the tier for the org, a space, a conversation or your new chats",
|
|
@@ -78,9 +94,14 @@ export const chooseAction = defineAction({
|
|
|
78
94
|
const where = [input.space, input.thread, input.mine].filter(Boolean).length;
|
|
79
95
|
if (where > 1)
|
|
80
96
|
throw invalid("Choose for one place at a time.");
|
|
81
|
-
// Over the cap: only who runs the org.
|
|
82
97
|
if (input.tier) {
|
|
83
|
-
const
|
|
98
|
+
const org = await choices(ctx).findOne({ _id: ORG_CHOICE });
|
|
99
|
+
const cap = org?.cap;
|
|
100
|
+
// Only the default: nobody chooses another below the org.
|
|
101
|
+
if (org?.fixed && where) {
|
|
102
|
+
throw failure("forbidden", "Every chat uses your org's default tier: its owners and admins chose so.", { public: true });
|
|
103
|
+
}
|
|
104
|
+
// Over the cap: only who runs the org.
|
|
84
105
|
if (aboveCap(tiers, input.tier, cap) && !await running(ctx)) {
|
|
85
106
|
throw failure("forbidden", `Your org's owners and admins let members use tiers up to ${tiers[cap].title}.`, { public: true });
|
|
86
107
|
}
|
|
@@ -107,58 +128,100 @@ export const chooseAction = defineAction({
|
|
|
107
128
|
},
|
|
108
129
|
});
|
|
109
130
|
export const capAction = defineAction({
|
|
110
|
-
description: "Sets
|
|
131
|
+
description: "Sets what the org's members may use: every tier, tiers up to one, or only the default",
|
|
111
132
|
input: {
|
|
112
133
|
type: "object",
|
|
113
|
-
properties: {
|
|
114
|
-
|
|
134
|
+
properties: {
|
|
135
|
+
/** The highest tier they may choose; null: any. */
|
|
136
|
+
tier: { type: ["string", "null"] },
|
|
137
|
+
/** Only the org's default: no space, conversation or person chooses another. */
|
|
138
|
+
fixed: { type: "boolean" },
|
|
139
|
+
},
|
|
115
140
|
additionalProperties: false,
|
|
116
141
|
},
|
|
117
142
|
allow: inPerson,
|
|
118
143
|
run: async (ctx, input) => {
|
|
119
144
|
await runsOrg(ctx, "set what members may use");
|
|
120
145
|
const { tiers } = await orgTiersOf(ctx.as());
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
const next = { ...
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
146
|
+
const cap = input.fixed ? null : input.tier ?? null;
|
|
147
|
+
if (cap !== null && !tiers[cap])
|
|
148
|
+
throw invalid(`There's no tier "${cap}".`);
|
|
149
|
+
const before = await choiceOf(ctx, ORG_CHOICE);
|
|
150
|
+
const next = { ...before, _id: ORG_CHOICE, at: new Date().toISOString() };
|
|
151
|
+
delete next.cap;
|
|
152
|
+
delete next.fixed;
|
|
153
|
+
if (input.fixed)
|
|
154
|
+
next.fixed = true;
|
|
155
|
+
else if (cap)
|
|
156
|
+
next.cap = cap;
|
|
157
|
+
await keep(ctx, before, next);
|
|
158
|
+
return { cap, fixed: !!input.fixed };
|
|
132
159
|
},
|
|
133
160
|
});
|
|
134
|
-
export const
|
|
135
|
-
description: "Sets
|
|
161
|
+
export const plansFirstAction = defineAction({
|
|
162
|
+
description: "Sets whether members' subscriptions are used whenever possible",
|
|
136
163
|
input: {
|
|
137
164
|
type: "object",
|
|
138
165
|
properties: {
|
|
139
|
-
/**
|
|
140
|
-
|
|
166
|
+
/** Every model on a member's plans before any on credits, then the tier's fallbacks. */
|
|
167
|
+
on: { type: "boolean" },
|
|
141
168
|
},
|
|
142
|
-
required: ["
|
|
169
|
+
required: ["on"],
|
|
143
170
|
additionalProperties: false,
|
|
144
171
|
},
|
|
145
172
|
allow: inPerson,
|
|
146
173
|
run: async (ctx, input) => {
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
const person = ctx.actor.id;
|
|
153
|
-
const id = personChoice(person);
|
|
154
|
-
const had = await choices(ctx).findOne({ _id: id });
|
|
155
|
-
const next = { ...had, _id: id, person, at: new Date().toISOString() };
|
|
156
|
-
if (order.length)
|
|
157
|
-
next.harnesses = order;
|
|
174
|
+
await runsOrg(ctx, "choose how members' subscriptions are used");
|
|
175
|
+
const before = await choiceOf(ctx, ORG_CHOICE);
|
|
176
|
+
const next = { ...before, _id: ORG_CHOICE, at: new Date().toISOString() };
|
|
177
|
+
if (input.on)
|
|
178
|
+
next.plansFirst = true;
|
|
158
179
|
else
|
|
159
|
-
delete next.
|
|
160
|
-
await keep(ctx,
|
|
161
|
-
return {
|
|
180
|
+
delete next.plansFirst;
|
|
181
|
+
await keep(ctx, before, next);
|
|
182
|
+
return { on: input.on };
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* Throws unless a plan of the app's runs `fallback` (a tier's fallbacks run
|
|
187
|
+
* on members' plans only), at the settings it's given. An app without plans
|
|
188
|
+
* never runs one: nothing to check.
|
|
189
|
+
*/
|
|
190
|
+
export async function checkFallback(ctx, fallback) {
|
|
191
|
+
const harnesses = plansInOrder(harnessesOf(ctx));
|
|
192
|
+
if (!harnesses.length)
|
|
193
|
+
return;
|
|
194
|
+
await ctx.call("models.check", {
|
|
195
|
+
model: { model: [], harnesses, planFallbacks: [fallback] },
|
|
196
|
+
port: "llm",
|
|
197
|
+
}).catch((error) => {
|
|
198
|
+
const named = primaryOf(ctx, fallback)?.id ?? JSON.stringify(fallback);
|
|
199
|
+
throw invalid(/No model chosen/.test(error.message)
|
|
200
|
+
? `No plan of the app's runs ${named}: a tier's fallbacks run on members' plans only.`
|
|
201
|
+
: error.message);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
export const orderAction = defineAction({
|
|
205
|
+
description: "Puts the org's tiers in order, lowest first",
|
|
206
|
+
transaction: true,
|
|
207
|
+
input: {
|
|
208
|
+
type: "object",
|
|
209
|
+
properties: { tiers: { type: "array", items: { type: "string" }, maxItems: 64 } },
|
|
210
|
+
required: ["tiers"],
|
|
211
|
+
additionalProperties: false,
|
|
212
|
+
},
|
|
213
|
+
allow: inPerson,
|
|
214
|
+
run: async (ctx, input) => {
|
|
215
|
+
await runsOrg(ctx, "change its tiers");
|
|
216
|
+
const { tiers } = await orgTiersOf(ctx.as());
|
|
217
|
+
const names = Object.keys(tiers);
|
|
218
|
+
if (input.tiers.length !== names.length || names.some((name) => !input.tiers.includes(name)))
|
|
219
|
+
throw invalid("Put each of the org's tiers in the order, once.");
|
|
220
|
+
const at = new Date().toISOString();
|
|
221
|
+
for (const [i, name] of input.tiers.entries()) {
|
|
222
|
+
await templates(ctx).updateOne({ _id: name }, { $set: { order: i + 1, at } }, { upsert: true });
|
|
223
|
+
}
|
|
224
|
+
return { tiers: input.tiers };
|
|
162
225
|
},
|
|
163
226
|
});
|
|
164
227
|
/** A name for a new tier from its title: `balanced`, `balanced-2`. */
|
|
@@ -181,6 +244,8 @@ export const saveAction = defineAction({
|
|
|
181
244
|
description: { type: "string", maxLength: 200 },
|
|
182
245
|
/** Chains by kind of work: models in order; null, back to the app's. */
|
|
183
246
|
kinds: { type: "object", additionalProperties: { type: ["array", "null"], maxItems: 8 } },
|
|
247
|
+
/** Models tried on members' plans after any chain, in order; null, back to the app's. */
|
|
248
|
+
fallbacks: { type: ["array", "null"], maxItems: 8 },
|
|
184
249
|
/** A new tier's chains, copied from this one. */
|
|
185
250
|
from: { type: "string" },
|
|
186
251
|
},
|
|
@@ -221,6 +286,16 @@ export const saveAction = defineAction({
|
|
|
221
286
|
await ctx.call("models.check", { model, port: "llm" });
|
|
222
287
|
chains[kind] = await settled(ctx, list, entryOf(base, kind, kinds) ?? undefined);
|
|
223
288
|
}
|
|
289
|
+
let fallbacks = making ? base?.fallbacks : had?.fallbacks;
|
|
290
|
+
if (input.fallbacks !== undefined) {
|
|
291
|
+
// One it had keeps its settings (its effort); a new one is as given.
|
|
292
|
+
const kept = new Map((tiers[name]?.fallbacks ?? []).map((f) => [primaryOf(ctx, f)?.id, f]));
|
|
293
|
+
fallbacks = input.fallbacks === null
|
|
294
|
+
? undefined
|
|
295
|
+
: input.fallbacks.map((f) => typeof f === "string" ? kept.get(f) ?? f : f);
|
|
296
|
+
for (const fallback of fallbacks ?? [])
|
|
297
|
+
await checkFallback(ctx, fallback);
|
|
298
|
+
}
|
|
224
299
|
const order = making
|
|
225
300
|
? Math.max(0, ...Object.values(tiers).map((t) => t.order ?? 0)) + 1
|
|
226
301
|
: had?.order;
|
|
@@ -232,6 +307,7 @@ export const saveAction = defineAction({
|
|
|
232
307
|
: {}),
|
|
233
308
|
...(order !== undefined ? { order } : {}),
|
|
234
309
|
...(Object.keys(chains).length ? { agents: chains } : {}),
|
|
310
|
+
...(fallbacks ? { fallbacks } : {}),
|
|
235
311
|
...(making || had?.made ? { made: true } : {}),
|
|
236
312
|
at: new Date().toISOString(),
|
|
237
313
|
}, { upsert: true });
|
|
@@ -276,7 +352,17 @@ export const restoreAction = defineAction({
|
|
|
276
352
|
if (!appTiersOf(ctx)[input.tier]) {
|
|
277
353
|
throw invalid(`"${input.tier}" isn't one of the app's tiers.`);
|
|
278
354
|
}
|
|
279
|
-
|
|
355
|
+
// As the app has it, in the place the org gave it.
|
|
356
|
+
const order = (await templates(ctx).findOne({ _id: input.tier }))?.order;
|
|
357
|
+
if (order === undefined)
|
|
358
|
+
await templates(ctx).deleteOne({ _id: input.tier });
|
|
359
|
+
else {
|
|
360
|
+
await templates(ctx).replaceOne({ _id: input.tier }, {
|
|
361
|
+
_id: input.tier,
|
|
362
|
+
order,
|
|
363
|
+
at: new Date().toISOString(),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
280
366
|
return { tier: input.tier };
|
|
281
367
|
},
|
|
282
368
|
});
|