@copilotz/team 0.0.0-stage → 1.0.0-rc.34
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/LICENSE +21 -0
- package/README.md +49 -2
- package/WORDS.md +200 -0
- package/contract.d.ts +8 -0
- package/contract.js +8 -0
- package/mod.d.ts +25 -0
- package/mod.js +25 -0
- package/package.json +63 -4
- package/team/actions/agent.d.ts +4 -0
- package/team/actions/agent.js +179 -0
- package/team/actions/define.d.ts +1 -0
- package/team/actions/define.js +27 -0
- package/team/collections/agent.d.ts +132 -0
- package/team/collections/agent.js +75 -0
- package/team/contract.d.ts +10 -0
- package/team/contract.js +1 -0
- package/team/mod.d.ts +21 -0
- package/team/mod.js +49 -0
- package/team/shared/definition.d.ts +3 -0
- package/team/shared/definition.js +10 -0
- package/team/views/web/agent-add.d.ts +14 -0
- package/team/views/web/agent-add.js +48 -0
- package/team/views/web/agent-fields.d.ts +33 -0
- package/team/views/web/agent-fields.js +88 -0
- package/team/views/web/agent-known.d.ts +22 -0
- package/team/views/web/agent-known.js +61 -0
- package/team/views/web/agent-new.d.ts +24 -0
- package/team/views/web/agent-new.js +129 -0
- package/team/views/web/agent-palette.d.ts +19 -0
- package/team/views/web/agent-palette.js +203 -0
- package/team/views/web/agent-steps.d.ts +23 -0
- package/team/views/web/agent-steps.js +56 -0
- package/team/views/web/agent.d.ts +17 -0
- package/team/views/web/agent.js +257 -0
- package/team/views/web/agents.d.ts +48 -0
- package/team/views/web/agents.js +59 -0
- package/team/views/web/model-pick.d.ts +25 -0
- package/team/views/web/model-pick.js +39 -0
- package/team/views/web/model-picker.d.ts +57 -0
- package/team/views/web/model-picker.js +218 -0
- package/team/views/web/places.d.ts +24 -0
- package/team/views/web/places.js +10 -0
- package/team/views/web/style.d.ts +9 -0
- package/team/views/web/style.js +246 -0
- package/team/views/web/words.d.ts +5 -0
- package/team/views/web/words.js +211 -0
- package/team/web.d.ts +22 -0
- package/team/web.js +41 -0
- package/tiers/actions/choose.d.ts +2 -0
- package/tiers/actions/choose.js +98 -0
- package/tiers/actions/model.d.ts +1 -0
- package/tiers/actions/model.js +36 -0
- package/tiers/collections/choice.d.ts +48 -0
- package/tiers/collections/choice.js +59 -0
- package/tiers/contract.d.ts +19 -0
- package/tiers/contract.js +1 -0
- package/tiers/mod.d.ts +54 -0
- package/tiers/mod.js +92 -0
- package/tiers/shared/shown.d.ts +87 -0
- package/tiers/shared/shown.js +155 -0
- package/tiers/shared/tiers.d.ts +103 -0
- package/tiers/shared/tiers.js +129 -0
- package/tiers/views/web/org.d.ts +38 -0
- package/tiers/views/web/org.js +142 -0
- package/tiers/views/web/space.d.ts +43 -0
- package/tiers/views/web/space.js +103 -0
- package/tiers/views/web/style.d.ts +7 -0
- package/tiers/views/web/style.js +87 -0
- package/tiers/views/web/words.d.ts +21 -0
- package/tiers/views/web/words.js +49 -0
- package/tiers/web.d.ts +18 -0
- package/tiers/web.js +40 -0
- package/web.d.ts +14 -0
- package/web.js +14 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/** Every word Team's web front end shows, to be changed by the app (`team.<key>`). */
|
|
2
|
+
import { defineWords } from "copilotz/web/words";
|
|
3
|
+
const team = {
|
|
4
|
+
// Names in a sentence
|
|
5
|
+
listJoin: ", ",
|
|
6
|
+
listEnd: "{rest} and {last}",
|
|
7
|
+
// Spaces, as they're named
|
|
8
|
+
personalSpace: "Personal",
|
|
9
|
+
// An agent's page
|
|
10
|
+
noSuchAgentTitle: "No such agent",
|
|
11
|
+
noSuchAgent: "No agent here by that name",
|
|
12
|
+
noSuchAgentBody: "It may have been deleted, or it works only in spaces you're not in.",
|
|
13
|
+
goHome: "Go home",
|
|
14
|
+
partOfApp: "Part of the app",
|
|
15
|
+
madeIn: "Made in {place}",
|
|
16
|
+
madeElsewhere: "Made elsewhere",
|
|
17
|
+
answersNewChatsHere: "Answers new chats here",
|
|
18
|
+
askAgent: "Ask {name}",
|
|
19
|
+
edit: "Edit",
|
|
20
|
+
editAgent: "Edit {name}",
|
|
21
|
+
moreMenu: "{name}: more",
|
|
22
|
+
makeAnswerIn: "Make it answer new chats in {place}",
|
|
23
|
+
addToSpaceMenu: "Add to a space…",
|
|
24
|
+
startFromIt: "Start a new agent from it…",
|
|
25
|
+
deleteMenu: "Delete {name}…",
|
|
26
|
+
addToTitle: "Add {name} to…",
|
|
27
|
+
addToNote: "It works there at once, as an editor: it answers chats there and adds to them.",
|
|
28
|
+
newLikeTitle: "New agent like {name}, in…",
|
|
29
|
+
newLikeNote: "It starts with its words, model and tools; it belongs to the space you pick.",
|
|
30
|
+
newAgentIn: "New agent in {place}",
|
|
31
|
+
startingFrom: "Starting from {name}.",
|
|
32
|
+
appAgentNotice: "Part of the app: it's set up in code, so it isn't changed here. To have one of your own like it, start a new agent from it.",
|
|
33
|
+
startFromShort: "Start from it",
|
|
34
|
+
managersChangeIt: "Those who manage {place} change it.",
|
|
35
|
+
managersChangeItElsewhere: "Those who manage the space it belongs to change it.",
|
|
36
|
+
worksIn: "Works in {count}",
|
|
37
|
+
addToSpace: "Add to a space",
|
|
38
|
+
answersNewChats: "Answers new chats",
|
|
39
|
+
roleViewer: "Viewer",
|
|
40
|
+
roleEditor: "Editor",
|
|
41
|
+
worksNowhere: "It doesn't work in any of your spaces.",
|
|
42
|
+
instructions: "Instructions",
|
|
43
|
+
modelAndTools: "Model and tools",
|
|
44
|
+
model: "Model",
|
|
45
|
+
thinks: "Thinks",
|
|
46
|
+
effort: "{effort} effort",
|
|
47
|
+
tools: "Tools",
|
|
48
|
+
toolsLabel: "Tools {count}",
|
|
49
|
+
noTools: "None: it only talks.",
|
|
50
|
+
showFewer: "Show fewer",
|
|
51
|
+
showAll: "Show all {count}",
|
|
52
|
+
modelsThenJoin: ", then ",
|
|
53
|
+
// Changing an agent
|
|
54
|
+
changeAgent: "Change {name}",
|
|
55
|
+
keepsHandle: "It keeps its name in chats, @{handle}, whatever it's shown as.",
|
|
56
|
+
cancel: "Cancel",
|
|
57
|
+
saveChanges: "Save changes",
|
|
58
|
+
// Deleting an agent
|
|
59
|
+
deleteTitle: "Delete {name}?",
|
|
60
|
+
deleteButton: "Delete {name}",
|
|
61
|
+
deleteLeavesBold: "It leaves every space it works in",
|
|
62
|
+
deleteLeavesNamed: "{bold}, {spaces} among them. Where it answered new chats, another agent there does.",
|
|
63
|
+
deleteLeaves: "{bold}. Where it answered new chats, another agent there does.",
|
|
64
|
+
deleteGoneBold: "Nobody can ask it anything again,",
|
|
65
|
+
deleteGone: "{bold} and it can't be brought back.",
|
|
66
|
+
deleteChatsBold: "Chats it was in stay as they are,",
|
|
67
|
+
deleteChats: "{bold} with what it said.",
|
|
68
|
+
// Spaces and deleting, in the command palette
|
|
69
|
+
findSpace: "Find a space",
|
|
70
|
+
spacesYouManage: "Spaces you manage",
|
|
71
|
+
justYou: "Just you",
|
|
72
|
+
keywordPersonal: "personal",
|
|
73
|
+
deleteStepNote: "It leaves every space it works in, and nobody can ask it anything again. Chats it was in stay as they are.",
|
|
74
|
+
deleteStepKeep: "Keep it",
|
|
75
|
+
// The agent fields
|
|
76
|
+
fieldName: "Name",
|
|
77
|
+
calledIn: "Called {handle} in chats",
|
|
78
|
+
nameHint: "What people call it: Maya is @maya in chats.",
|
|
79
|
+
namePlaceholder: "Maya",
|
|
80
|
+
emoji: "Emoji",
|
|
81
|
+
noEmoji: "None: its initial",
|
|
82
|
+
anotherEmoji: "Another emoji",
|
|
83
|
+
otherEmoji: "Other",
|
|
84
|
+
fieldDoes: "What should it do?",
|
|
85
|
+
doesHint: "A line or two, for people, and for other agents deciding whom to ask.",
|
|
86
|
+
doesPlaceholder: "Writes launch copy in our voice, and checks facts with the researcher.",
|
|
87
|
+
modelHint: "What it thinks with.",
|
|
88
|
+
rewriteForMe: "Rewrite them for me",
|
|
89
|
+
writeForMe: "Write them for me",
|
|
90
|
+
sayNameFirst: "Say its name and what it should do first",
|
|
91
|
+
youArePlaceholder: "You are {name}. You…",
|
|
92
|
+
youAreDefaultName: "Maya",
|
|
93
|
+
writingFor: "Writing {name}'s instructions…",
|
|
94
|
+
draftNote: "Written for you from what it should do: read them through, and change what you like.",
|
|
95
|
+
undo: "Undo",
|
|
96
|
+
instructionsHint: "What it's told every time it works: who it is, what it does, and how it answers.",
|
|
97
|
+
instructionsEmptyHint: "Say its name and what it should do, and it can write them for you.",
|
|
98
|
+
toolsOf: "{chosen} of {offered}",
|
|
99
|
+
toolsChooseDone: "Done",
|
|
100
|
+
toolsChoose: "Choose",
|
|
101
|
+
toolsAll: "All",
|
|
102
|
+
toolsNone: "None",
|
|
103
|
+
toolsMore: "+{count} more",
|
|
104
|
+
// Making an agent
|
|
105
|
+
newAgentForm: "A new agent",
|
|
106
|
+
agentsYouKnow: "Agents you know",
|
|
107
|
+
startFrom: "Start from",
|
|
108
|
+
startBlank: "Nothing: a blank agent",
|
|
109
|
+
worksInAs: "Works in {place} as",
|
|
110
|
+
belongsHint: "{lets}. It belongs to {place}: those who manage it change it.",
|
|
111
|
+
createNamed: "Create {name}",
|
|
112
|
+
createAgent: "Create agent",
|
|
113
|
+
// Made
|
|
114
|
+
worksNow: "{name} works in {place} now",
|
|
115
|
+
askHandle: "Ask {handle} in any chat here.",
|
|
116
|
+
readsOnly: "It reads what's here for chats where it's an editor; it doesn't answer here.",
|
|
117
|
+
makeAnswer: "Make it answer new chats",
|
|
118
|
+
openPage: "Open its page",
|
|
119
|
+
makeAnother: "Make another",
|
|
120
|
+
// Adding an agent to a space
|
|
121
|
+
notYourSpace: "This space isn't one of yours.",
|
|
122
|
+
archivedSpace: "{place} is archived: restore it to add agents.",
|
|
123
|
+
managersAdd: "Those who manage {place} add agents to it.",
|
|
124
|
+
addAnAgentTitle: "Add an agent to {place}",
|
|
125
|
+
addAnAgentNote: "Agents work for whoever asks them, and reach only what that person can.",
|
|
126
|
+
// Agents you know
|
|
127
|
+
oneOfApps: "One of the app's agents",
|
|
128
|
+
madeInOther: "Made in another space",
|
|
129
|
+
findAgent: "Find an agent",
|
|
130
|
+
findAgentKnown: "Find an agent you know",
|
|
131
|
+
knownIntro: "Agents you know, from the app and your spaces",
|
|
132
|
+
addsAs: "Adds as",
|
|
133
|
+
createNewAgent: "Create a new agent",
|
|
134
|
+
createNewAgentBody: "Say what it should do; it can write its own instructions.",
|
|
135
|
+
addAgentTo: "Add {name} to {place}",
|
|
136
|
+
add: "Add",
|
|
137
|
+
noneCalled: "No agent you know is called “{search}”.",
|
|
138
|
+
allWorkHere: "Every agent you know works in {place} already.",
|
|
139
|
+
worksNowNames: {
|
|
140
|
+
one: "{names} works in {place} now.",
|
|
141
|
+
other: "{names} work in {place} now.",
|
|
142
|
+
},
|
|
143
|
+
// The palette
|
|
144
|
+
paletteThisAgent: "This agent",
|
|
145
|
+
paletteThisSpace: "This space",
|
|
146
|
+
paletteAgents: "Agents",
|
|
147
|
+
paletteCreate: "Create",
|
|
148
|
+
makeNamedAnswerIn: "Make {name} answer new chats in {place}",
|
|
149
|
+
makeNamedAnswer: "Make {name} answer new chats",
|
|
150
|
+
keywordDefault: "default",
|
|
151
|
+
keywordAnswer: "answer",
|
|
152
|
+
keywordNewChats: "new chats",
|
|
153
|
+
addNamedTo: "Add {name} to a space…",
|
|
154
|
+
addNamedNote: "It works there at once, as an editor.",
|
|
155
|
+
keywordMember: "member",
|
|
156
|
+
keywordJoin: "join",
|
|
157
|
+
keywordWork: "work",
|
|
158
|
+
editNamed: "Edit {name}",
|
|
159
|
+
keywordChange: "change",
|
|
160
|
+
keywordInstructions: "instructions",
|
|
161
|
+
keywordRename: "rename",
|
|
162
|
+
startNewFrom: "Start a new agent from {name}…",
|
|
163
|
+
keywordCopy: "copy",
|
|
164
|
+
keywordLike: "like",
|
|
165
|
+
keywordCreate: "create",
|
|
166
|
+
addAnAgentTo: "Add an agent to {place}…",
|
|
167
|
+
keywordInvite: "invite",
|
|
168
|
+
keywordAgent: "agent",
|
|
169
|
+
worksHere: "@{id} · works here",
|
|
170
|
+
newAgent: "New agent…",
|
|
171
|
+
newAgentInHere: "In {place}",
|
|
172
|
+
keywordMake: "make",
|
|
173
|
+
newAgentInStep: "New agent in…",
|
|
174
|
+
newAgentInNote: "It belongs to the space you pick: those who manage it change it.",
|
|
175
|
+
// The model picker
|
|
176
|
+
chooseModel: "Choose a model",
|
|
177
|
+
needsKey: "Needs a key",
|
|
178
|
+
yourKey: "Your key",
|
|
179
|
+
providerModels: { one: "{count} model", other: "{count} models" },
|
|
180
|
+
searchModels: "Search providers and models",
|
|
181
|
+
readyToUse: "Ready to use",
|
|
182
|
+
withOwnKey: "With your own key",
|
|
183
|
+
providers: "Providers",
|
|
184
|
+
models: "Models",
|
|
185
|
+
nothingMatches: "Nothing matches that.",
|
|
186
|
+
allProviders: "All providers",
|
|
187
|
+
noKeyForProvider: "This org has no key for {provider}. Its owners and admins can add one.",
|
|
188
|
+
apiKeyLabel: "Your {provider} API key",
|
|
189
|
+
pasteIt: "Paste it here",
|
|
190
|
+
save: "Save",
|
|
191
|
+
keyNote: "Encrypted, and never shown again. All of this org's agents use it for {provider}, and {provider} charges your account.",
|
|
192
|
+
orgKey: "This org's key {hint}",
|
|
193
|
+
usesAppKey: "Uses the app's key",
|
|
194
|
+
replace: "Replace",
|
|
195
|
+
useOwnKey: "Use your own key",
|
|
196
|
+
remove: "Remove",
|
|
197
|
+
change: "Change",
|
|
198
|
+
// What a model costs and can do
|
|
199
|
+
noCreditsUsed: "No credits used",
|
|
200
|
+
priceLine: "{input} in · {output} out per 1M tokens",
|
|
201
|
+
priceOwnKey: "No credits used: your key, at {price}",
|
|
202
|
+
contextSize: "{size} context",
|
|
203
|
+
mediaImage: "Images",
|
|
204
|
+
mediaPdf: "PDFs",
|
|
205
|
+
mediaAudio: "Audio",
|
|
206
|
+
mediaVideo: "Video",
|
|
207
|
+
reasoning: "Reasoning",
|
|
208
|
+
};
|
|
209
|
+
export const say = defineWords("team", team);
|
|
210
|
+
/** Every word of team's front end, by area (WORDS.md lists them). */
|
|
211
|
+
export const PHRASES = { team };
|
package/team/web.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team's web front end, for the browser: making and changing agents. Each
|
|
3
|
+
* agent has a page (`/agent/<id>`, kind `agent`): who it is, where it works
|
|
4
|
+
* among the person's spaces, what it's told; changed in place and deleted
|
|
5
|
+
* by those who manage where it belongs, the app's own read only (a manager
|
|
6
|
+
* starts a new one from it). Adding an agent to a space (`agent.add`: one
|
|
7
|
+
* the person has met, or a new one made there, its instructions written
|
|
8
|
+
* for them if they like) is the Agents tab of spaces' invite surface
|
|
9
|
+
* (spaces' `spaceInvite` resource, named here; Personal spaces too). In
|
|
10
|
+
* the command palette (`agent.palette`): agents to go to, adding one,
|
|
11
|
+
* making one, having one answer new chats, and what to do with the one
|
|
12
|
+
* open. Chat's front end shows agents in chats; spaces' adds them. Other
|
|
13
|
+
* front ends choose a model with the same picker (`model.pick`: item
|
|
14
|
+
* `{ value }`, hints `{ action, input, look? }`, calling `action` with what's
|
|
15
|
+
* chosen). Add it beside them:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* await web({ plugins: [webShell, chatWeb, spacesWeb, teamWeb], root });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import { type Plugin } from "copilotz";
|
|
22
|
+
export declare const teamWeb: Plugin;
|
package/team/web.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team's web front end, for the browser: making and changing agents. Each
|
|
3
|
+
* agent has a page (`/agent/<id>`, kind `agent`): who it is, where it works
|
|
4
|
+
* among the person's spaces, what it's told; changed in place and deleted
|
|
5
|
+
* by those who manage where it belongs, the app's own read only (a manager
|
|
6
|
+
* starts a new one from it). Adding an agent to a space (`agent.add`: one
|
|
7
|
+
* the person has met, or a new one made there, its instructions written
|
|
8
|
+
* for them if they like) is the Agents tab of spaces' invite surface
|
|
9
|
+
* (spaces' `spaceInvite` resource, named here; Personal spaces too). In
|
|
10
|
+
* the command palette (`agent.palette`): agents to go to, adding one,
|
|
11
|
+
* making one, having one answer new chats, and what to do with the one
|
|
12
|
+
* open. Chat's front end shows agents in chats; spaces' adds them. Other
|
|
13
|
+
* front ends choose a model with the same picker (`model.pick`: item
|
|
14
|
+
* `{ value }`, hints `{ action, input, look? }`, calling `action` with what's
|
|
15
|
+
* chosen). Add it beside them:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* await web({ plugins: [webShell, chatWeb, spacesWeb, teamWeb], root });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import { definePlugin } from "copilotz";
|
|
22
|
+
import { agentView } from "./views/web/agent.js";
|
|
23
|
+
import { agentAddView } from "./views/web/agent-add.js";
|
|
24
|
+
import { agentPaletteView } from "./views/web/agent-palette.js";
|
|
25
|
+
import { modelPickView } from "./views/web/model-pick.js";
|
|
26
|
+
export const teamWeb = definePlugin({
|
|
27
|
+
name: "team-web",
|
|
28
|
+
requires: ["team", "web-shell"],
|
|
29
|
+
views: {
|
|
30
|
+
agent: agentView,
|
|
31
|
+
"agent.add": agentAddView,
|
|
32
|
+
"agent.palette": agentPaletteView,
|
|
33
|
+
"model.pick": modelPickView,
|
|
34
|
+
},
|
|
35
|
+
resources: {
|
|
36
|
+
spaceInvite: {
|
|
37
|
+
agents: { title: "Agents", view: "agent.add", order: 20, personal: true },
|
|
38
|
+
},
|
|
39
|
+
palette: { agents: { view: "agent.palette", order: 25 } },
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choosing the app's agents' models, for the org or for one space, in person.
|
|
3
|
+
* The org's are changed by its owners and admins, a space's by its managers;
|
|
4
|
+
* which tier a space takes isn't limited: the org's budget bounds what it
|
|
5
|
+
* spends. A change applies from each conversation's next reply.
|
|
6
|
+
*
|
|
7
|
+
* - `tiers.choose` `{ space?, tier, picks? }`: the tier by its name (null:
|
|
8
|
+
* the one above, the org's or the plan's), and `picks: null` to drop every
|
|
9
|
+
* agent's own pick there too (back to the tier as it is).
|
|
10
|
+
* - `tiers.pick` `{ space?, agent, model }`: a model for one of the app's
|
|
11
|
+
* agents there, as an agent's `model` takes one (null: back to the tier's).
|
|
12
|
+
* It's checked as an agent's would be, and keeps the tier's list behind it;
|
|
13
|
+
* as it runs, it gets the `maxTokens` of the entry it replaces, and its
|
|
14
|
+
* `effort` when the picked model takes it.
|
|
15
|
+
*/
|
|
16
|
+
import { defineAction, inPerson, invalid } from "copilotz";
|
|
17
|
+
import { must, ORG } from "copilotz/plugins/access/contract";
|
|
18
|
+
import { agentsOf } from "copilotz/plugins/agents/contract";
|
|
19
|
+
import { ORG_CHOICE, spaceChoice, tiersOf } from "../shared/tiers.js";
|
|
20
|
+
/** Where a choice is kept, once the caller may change it. */
|
|
21
|
+
async function choiceFor(ctx, space) {
|
|
22
|
+
if (!space) {
|
|
23
|
+
await must(ctx, "manage", ORG, "Only the org's owners and admins change its agents' models.");
|
|
24
|
+
return ORG_CHOICE;
|
|
25
|
+
}
|
|
26
|
+
await must(ctx, "manage", space, "Only this space's managers change its agents' models.");
|
|
27
|
+
return spaceChoice(space);
|
|
28
|
+
}
|
|
29
|
+
/** Changes a choice; one left with nothing in it is gone, so what's above applies. */
|
|
30
|
+
async function change(ctx, space, to) {
|
|
31
|
+
const id = await choiceFor(ctx, space);
|
|
32
|
+
const docs = ctx.as().db.collection("modelChoice");
|
|
33
|
+
const had = await docs.findOne({ _id: id });
|
|
34
|
+
const next = to({ ...(had?.tier ? { tier: had.tier } : {}), custom: { ...had?.custom } });
|
|
35
|
+
const custom = next.custom && Object.keys(next.custom).length ? next.custom : undefined;
|
|
36
|
+
if (!next.tier && !custom) {
|
|
37
|
+
if (had)
|
|
38
|
+
await docs.deleteOne({ _id: id });
|
|
39
|
+
return { tier: null, custom: {} };
|
|
40
|
+
}
|
|
41
|
+
await docs.replaceOne({ _id: id }, {
|
|
42
|
+
_id: id,
|
|
43
|
+
...(space ? { space } : {}),
|
|
44
|
+
...(next.tier ? { tier: next.tier } : {}),
|
|
45
|
+
...(custom ? { custom } : {}),
|
|
46
|
+
at: new Date().toISOString(),
|
|
47
|
+
}, { upsert: true });
|
|
48
|
+
return { tier: next.tier ?? null, custom: custom ?? {} };
|
|
49
|
+
}
|
|
50
|
+
export const chooseAction = defineAction({
|
|
51
|
+
description: "Chooses the tier of models the app's agents use, in the org or a space",
|
|
52
|
+
input: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
space: { type: "string" },
|
|
56
|
+
tier: { type: ["string", "null"] },
|
|
57
|
+
picks: { type: "null" },
|
|
58
|
+
},
|
|
59
|
+
required: ["tier"],
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
},
|
|
62
|
+
allow: inPerson,
|
|
63
|
+
run: (ctx, input) => {
|
|
64
|
+
if (input.tier !== null && !Object.hasOwn(tiersOf(ctx), input.tier)) {
|
|
65
|
+
throw invalid(`There's no tier "${input.tier}".`);
|
|
66
|
+
}
|
|
67
|
+
return change(ctx, input.space, (had) => ({
|
|
68
|
+
...(input.tier ? { tier: input.tier } : {}),
|
|
69
|
+
...(input.picks === null ? {} : { custom: had.custom }),
|
|
70
|
+
}));
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
export const pickAction = defineAction({
|
|
74
|
+
description: "Picks the model one of the app's agents uses, in the org or a space",
|
|
75
|
+
input: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
space: { type: "string" },
|
|
79
|
+
agent: { type: "string", minLength: 1 },
|
|
80
|
+
model: {},
|
|
81
|
+
},
|
|
82
|
+
required: ["agent", "model"],
|
|
83
|
+
additionalProperties: false,
|
|
84
|
+
},
|
|
85
|
+
allow: inPerson,
|
|
86
|
+
run: async (ctx, input) => {
|
|
87
|
+
if (!agentsOf(ctx)[input.agent]) {
|
|
88
|
+
throw invalid(`"${input.agent}" isn't one of the app's agents: it keeps its own model.`);
|
|
89
|
+
}
|
|
90
|
+
const model = input.model;
|
|
91
|
+
if (model !== null)
|
|
92
|
+
await ctx.call("models.check", { model, port: "llm" });
|
|
93
|
+
return change(ctx, input.space, (had) => {
|
|
94
|
+
const { [input.agent]: _, ...rest } = had.custom ?? {};
|
|
95
|
+
return { ...had, custom: model === null ? rest : { ...rest, [input.agent]: model } };
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const modelAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tiers.model` `{ agent, space? }`: the model one of the app's agents thinks
|
|
3
|
+
* with in a space (chat's `agentModel` resource names it): what's picked for it
|
|
4
|
+
* there, the space's tier, the org's pick, the org's tier, the plan's tier
|
|
5
|
+
* (see shared/tiers.ts), or null, its own. Asked on every run of a turn, so it
|
|
6
|
+
* only reads by `_id`, which the owner keeps cached: the space's choice and
|
|
7
|
+
* the org's, and the plan's tier (credits' `billing.tier`, a read by `_id` too).
|
|
8
|
+
* A pick gets the `maxTokens` of the entry it replaces, and its `effort` when
|
|
9
|
+
* the picked model takes it (`models.efforts`, the catalog's: nothing read).
|
|
10
|
+
*/
|
|
11
|
+
import { defineAction } from "copilotz";
|
|
12
|
+
import { carried, ORG_CHOICE, resolve, spaceChoice } from "../shared/tiers.js";
|
|
13
|
+
import { agentsOf } from "copilotz/plugins/agents/contract";
|
|
14
|
+
export const modelAction = defineAction({
|
|
15
|
+
description: "The model one of the app's agents thinks with in a space",
|
|
16
|
+
record: false,
|
|
17
|
+
input: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: { agent: { type: "string" }, space: { type: "string" } },
|
|
20
|
+
required: ["agent"],
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
},
|
|
23
|
+
run: async (ctx, input) => {
|
|
24
|
+
// Agents people make keep their own model, and cost nothing to ask about.
|
|
25
|
+
if (!agentsOf(ctx)[input.agent])
|
|
26
|
+
return null;
|
|
27
|
+
const choices = ctx.as().db.collection("modelChoice");
|
|
28
|
+
const source = ctx.resources.planTier;
|
|
29
|
+
const [space, org, plan] = await Promise.all([
|
|
30
|
+
input.space ? choices.findOne({ _id: spaceChoice(input.space) }) : null,
|
|
31
|
+
choices.findOne({ _id: ORG_CHOICE }),
|
|
32
|
+
source?.action ? ctx.as().call(source.action, {}) : null,
|
|
33
|
+
]);
|
|
34
|
+
return await carried(ctx, resolve(ctx, input.agent, { space, org, plan }));
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ModelRef } from "copilotz/plugins/models/contract";
|
|
2
|
+
export type ModelChoice = {
|
|
3
|
+
_id: string;
|
|
4
|
+
space?: string;
|
|
5
|
+
tier?: string;
|
|
6
|
+
custom?: Record<string, ModelRef>;
|
|
7
|
+
at: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const modelChoice: {
|
|
10
|
+
schema: {
|
|
11
|
+
readonly type: "object";
|
|
12
|
+
readonly properties: {
|
|
13
|
+
/** The space it's for; none: the org's. */
|
|
14
|
+
readonly space: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
};
|
|
17
|
+
/** A tier by its name; none: the one above (the org's, then the plan's). */
|
|
18
|
+
readonly tier: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
};
|
|
21
|
+
/** Models picked for some of the app's agents, by name, as an agent's `model` takes one. */
|
|
22
|
+
readonly custom: {
|
|
23
|
+
readonly type: "object";
|
|
24
|
+
};
|
|
25
|
+
readonly at: {
|
|
26
|
+
readonly type: "string";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly required: readonly ["at"];
|
|
30
|
+
};
|
|
31
|
+
events?: boolean;
|
|
32
|
+
records?: boolean;
|
|
33
|
+
durable?: false;
|
|
34
|
+
indexes?: string[][];
|
|
35
|
+
private?: string[];
|
|
36
|
+
queries?: Record<string, import("copilotz").QueryDef<{
|
|
37
|
+
[x: string]: unknown;
|
|
38
|
+
space?: string | undefined;
|
|
39
|
+
tier?: string | undefined;
|
|
40
|
+
custom?: {
|
|
41
|
+
[x: string]: unknown;
|
|
42
|
+
} | undefined;
|
|
43
|
+
at: string;
|
|
44
|
+
} & {
|
|
45
|
+
_id: string;
|
|
46
|
+
}>> | undefined;
|
|
47
|
+
vectors?: string[];
|
|
48
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an org and its spaces chose for the app's agents' models: the org's
|
|
3
|
+
* (`_id: "org"`) and each space's (`space:<id>`), each a tier by its name and
|
|
4
|
+
* models picked for some agents. Never a copy of a tier's lists: retuning a
|
|
5
|
+
* tier moves everyone on it. Changed only through `tiers.choose` and
|
|
6
|
+
* `tiers.pick`, which say who may; read by `_id`, so a turn's asking costs
|
|
7
|
+
* what the owner has cached.
|
|
8
|
+
*
|
|
9
|
+
* Queries, for front ends, as the person looking:
|
|
10
|
+
* - `offered` `{ space? }`: the tiers on offer with each agent's model and a
|
|
11
|
+
* typical reply's price at this org's prices, what the org chose and the
|
|
12
|
+
* plan gives, and with `space`, what the space chose; then what applies
|
|
13
|
+
* there, each agent's model and where it comes from. Anyone in the org reads
|
|
14
|
+
* the org's; a space's, those who reach it.
|
|
15
|
+
* - `agent` `{ agent, space }`: one of the app's agents in a space, its model
|
|
16
|
+
* and where it comes from, and when it's picked for the space, where taking
|
|
17
|
+
* the pick back leaves it (`without`); null for an agent that isn't the app's.
|
|
18
|
+
*/
|
|
19
|
+
import { defineCollection, forbidden, people } from "copilotz";
|
|
20
|
+
import { agentAt, shownAt } from "../shared/shown.js";
|
|
21
|
+
const choiceSchema = {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
/** The space it's for; none: the org's. */
|
|
25
|
+
space: { type: "string" },
|
|
26
|
+
/** A tier by its name; none: the one above (the org's, then the plan's). */
|
|
27
|
+
tier: { type: "string" },
|
|
28
|
+
/** Models picked for some of the app's agents, by name, as an agent's `model` takes one. */
|
|
29
|
+
custom: { type: "object" },
|
|
30
|
+
at: { type: "string" },
|
|
31
|
+
},
|
|
32
|
+
required: ["at"],
|
|
33
|
+
};
|
|
34
|
+
/** Only someone who reaches the space reads what it chose: the rules say whether they do. */
|
|
35
|
+
async function reached(ctx, space) {
|
|
36
|
+
const found = await ctx.db.collection("space").findOne({ _id: space });
|
|
37
|
+
if (!found)
|
|
38
|
+
throw forbidden("You can't read that space.");
|
|
39
|
+
}
|
|
40
|
+
export const modelChoice = defineCollection({
|
|
41
|
+
schema: choiceSchema,
|
|
42
|
+
queries: {
|
|
43
|
+
offered: {
|
|
44
|
+
allow: people,
|
|
45
|
+
run: async (_, params, ctx) => {
|
|
46
|
+
if (params.space)
|
|
47
|
+
await reached(ctx, params.space);
|
|
48
|
+
return await shownAt(ctx, params.space);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
agent: {
|
|
52
|
+
allow: people,
|
|
53
|
+
run: async (_, params, ctx) => {
|
|
54
|
+
await reached(ctx, params.space);
|
|
55
|
+
return await agentAt(ctx, params.agent, params.space);
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tiers plugin's contract: the shapes of a tier (its `tiers` resource), of
|
|
3
|
+
* what an org or a space chose, and of what its queries answer, and the
|
|
4
|
+
* resource kind it reads (`planTier`). The rest is reached by name: its
|
|
5
|
+
* collection `modelChoice`, its queries (`modelChoice.offered`,
|
|
6
|
+
* `modelChoice.agent`) and its Actions (`tiers.model`, `tiers.choose`,
|
|
7
|
+
* `tiers.pick`).
|
|
8
|
+
*/
|
|
9
|
+
export type { Choice, From, Tier } from "./shared/tiers.js";
|
|
10
|
+
export type { ModelChoice } from "./collections/choice.js";
|
|
11
|
+
export type { AgentNow, ChoiceShown, ModelShown, Shown, TierShown } from "./shared/shown.js";
|
|
12
|
+
/**
|
|
13
|
+
* A `planTier` resource: the Action saying which tier the org's plan gives its
|
|
14
|
+
* agents while the org hasn't chosen (credits' `billing.tier`), `{}` in, a
|
|
15
|
+
* tier's name or null out.
|
|
16
|
+
*/
|
|
17
|
+
export type PlanTier = {
|
|
18
|
+
action: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/tiers/mod.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiers: which models the app's agents think with, chosen by what the work
|
|
3
|
+
* needs rather than model by model. The app declares its tiers (its `tiers`
|
|
4
|
+
* resource): each a title, what it's good for, and a model for each of its
|
|
5
|
+
* agents, as an agent's `model` takes one (one, settings around one, or a list
|
|
6
|
+
* tried in order). An org chooses one, and a space can choose another:
|
|
7
|
+
*
|
|
8
|
+
* - **Who chooses, first that applies:** a model picked for the agent in the
|
|
9
|
+
* space, the space's tier, a model picked for it by the org, the org's tier,
|
|
10
|
+
* then the tier the org's plan gives (the `planTier` resource, which credits
|
|
11
|
+
* fills); else the agent's own model. A tier that doesn't name an agent
|
|
12
|
+
* leaves it on its own. A pick keeps the tier's list behind it, so a model
|
|
13
|
+
* that fails falls back as before, and the `maxTokens` of the entry it
|
|
14
|
+
* replaces, with its `effort` when the picked model takes it.
|
|
15
|
+
* - **Names, never copies:** an org or a space keeps a tier's name
|
|
16
|
+
* (`modelChoice`), so retuning a tier moves everyone on it.
|
|
17
|
+
* - **Who may:** the org's owners and admins choose for the org, a space's
|
|
18
|
+
* managers for the space (`tiers.choose`, `tiers.pick`); everyone who
|
|
19
|
+
* reaches them sees what was chosen (`modelChoice.offered`,
|
|
20
|
+
* `modelChoice.agent`). Which tier a space takes isn't limited: the org's
|
|
21
|
+
* budget bounds what it spends.
|
|
22
|
+
* - **Every turn:** chat asks `tiers.model` through its `agentModel` resource,
|
|
23
|
+
* for the app's agents only; agents people make keep their own model. A
|
|
24
|
+
* change applies from each conversation's next reply.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* plugins: [models, chat, ...access, tiers, definePlugin({
|
|
28
|
+
* name: "app",
|
|
29
|
+
* resources: {
|
|
30
|
+
* tiers: {
|
|
31
|
+
* everyday: {
|
|
32
|
+
* title: "Everyday",
|
|
33
|
+
* description: "Quick answers, routine work, volume",
|
|
34
|
+
* order: 1,
|
|
35
|
+
* agents: { north: "anthropic/claude-haiku-5-5", east: "openai/gpt-6-luna" },
|
|
36
|
+
* },
|
|
37
|
+
* expert: {
|
|
38
|
+
* title: "Expert",
|
|
39
|
+
* description: "Hard problems, decisions that matter",
|
|
40
|
+
* order: 3,
|
|
41
|
+
* agents: {
|
|
42
|
+
* north: [{ model: "anthropic/claude-opus-5-5", effort: "medium" }, "openai/gpt-6.1-sol"],
|
|
43
|
+
* east: { model: "anthropic/claude-sonnet-5-5", effort: "high" },
|
|
44
|
+
* },
|
|
45
|
+
* },
|
|
46
|
+
* },
|
|
47
|
+
* },
|
|
48
|
+
* })]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
import { type Plugin } from "copilotz";
|
|
52
|
+
export * from "./contract.js";
|
|
53
|
+
export declare const tiers: Plugin;
|
|
54
|
+
export default tiers;
|