@copilotz/team 1.0.0-rc.54 → 1.0.0-rc.55

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.
Files changed (66) hide show
  1. package/WORDS.md +156 -0
  2. package/package.json +2 -2
  3. package/team/actions/agent.d.ts +10 -0
  4. package/team/actions/agent.js +226 -7
  5. package/team/actions/define.js +7 -3
  6. package/team/collections/agent.d.ts +52 -7
  7. package/team/collections/agent.js +56 -5
  8. package/team/mod.d.ts +7 -0
  9. package/team/mod.js +14 -1
  10. package/team/resources/propose.d.ts +1 -0
  11. package/team/resources/propose.js +97 -0
  12. package/team/shared/definition.d.ts +1 -1
  13. package/team/shared/definition.js +5 -4
  14. package/team/shared/everywhere.d.ts +11 -0
  15. package/team/shared/everywhere.js +29 -0
  16. package/team/views/web/agent-add.js +14 -4
  17. package/team/views/web/agent-describe.d.ts +38 -0
  18. package/team/views/web/agent-describe.js +44 -0
  19. package/team/views/web/agent-fields.d.ts +3 -1
  20. package/team/views/web/agent-fields.js +2 -2
  21. package/team/views/web/agent-known.js +2 -1
  22. package/team/views/web/agent-new.d.ts +4 -1
  23. package/team/views/web/agent-new.js +26 -5
  24. package/team/views/web/agent-org.d.ts +12 -0
  25. package/team/views/web/agent-org.js +89 -0
  26. package/team/views/web/agent.d.ts +7 -4
  27. package/team/views/web/agent.js +81 -28
  28. package/team/views/web/model-pick.d.ts +3 -1
  29. package/team/views/web/model-pick.js +4 -1
  30. package/team/views/web/style.d.ts +1 -1
  31. package/team/views/web/style.js +5 -0
  32. package/team/views/web/words.d.ts +1 -1
  33. package/team/views/web/words.js +28 -0
  34. package/team/web.js +2 -0
  35. package/tiers/actions/choose.d.ts +5 -1
  36. package/tiers/actions/choose.js +247 -66
  37. package/tiers/actions/model.js +31 -22
  38. package/tiers/collections/choice.d.ts +17 -10
  39. package/tiers/collections/choice.js +39 -27
  40. package/tiers/collections/template.d.ts +90 -0
  41. package/tiers/collections/template.js +41 -0
  42. package/tiers/contract.d.ts +10 -8
  43. package/tiers/mod.d.ts +30 -21
  44. package/tiers/mod.js +45 -36
  45. package/tiers/shared/shown.d.ts +131 -49
  46. package/tiers/shared/shown.js +192 -98
  47. package/tiers/shared/tiers.d.ts +105 -62
  48. package/tiers/shared/tiers.js +127 -86
  49. package/tiers/views/web/composer.d.ts +12 -0
  50. package/tiers/views/web/composer.js +79 -0
  51. package/tiers/views/web/org.d.ts +44 -21
  52. package/tiers/views/web/org.js +231 -84
  53. package/tiers/views/web/say.d.ts +138 -0
  54. package/tiers/views/web/say.js +142 -0
  55. package/tiers/views/web/setup.d.ts +23 -0
  56. package/tiers/views/web/setup.js +80 -0
  57. package/tiers/views/web/space.d.ts +8 -20
  58. package/tiers/views/web/space.js +30 -59
  59. package/tiers/views/web/style.d.ts +1 -1
  60. package/tiers/views/web/style.js +98 -4
  61. package/tiers/views/web/team.d.ts +38 -0
  62. package/tiers/views/web/team.js +118 -0
  63. package/tiers/views/web/words.d.ts +36 -16
  64. package/tiers/views/web/words.js +102 -35
  65. package/tiers/web.d.ts +18 -9
  66. package/tiers/web.js +36 -10
package/WORDS.md CHANGED
@@ -22,6 +22,8 @@ Generated: `deno run -A packages/team/tests/words.ts`.
22
22
  | `team.addToNote` | It works there at once, as an editor: it answers chats there and adds to them. |
23
23
  | `team.addToSpace` | Add to a space |
24
24
  | `team.addToSpaceMenu` | Add to a space… |
25
+ | `team.addToTeam` | Add to the team |
26
+ | `team.addToTeamNamed` | Add {name} to the team |
25
27
  | `team.addToTitle` | Add {name} to… |
26
28
  | `team.agentsYouKnow` | Agents you know |
27
29
  | `team.allProviders` | All providers |
@@ -34,11 +36,13 @@ Generated: `deno run -A packages/team/tests/words.ts`.
34
36
  | `team.archivedSpace` | {place} is archived: restore it to add agents. |
35
37
  | `team.askAgent` | Ask {name} |
36
38
  | `team.askHandle` | Ask {handle} in any chat here. |
39
+ | `team.back` | Back |
37
40
  | `team.belongsHint` | {lets}. It belongs to {place}: those who manage it change it. |
38
41
  | `team.calledIn` | Called {handle} in chats |
39
42
  | `team.cancel` | Cancel |
40
43
  | `team.change` | Change |
41
44
  | `team.changeAgent` | Change {name} |
45
+ | `team.changedForOrg` | Changed for your org |
42
46
  | `team.chooseModel` | Choose a model |
43
47
  | `team.contextSize` | {size} context |
44
48
  | `team.createAgent` | Create agent |
@@ -57,8 +61,13 @@ Generated: `deno run -A packages/team/tests/words.ts`.
57
61
  | `team.deleteStepKeep` | Keep it |
58
62
  | `team.deleteStepNote` | It leaves every space it works in, and nobody can ask it anything again. Chats it was in stay as they are. |
59
63
  | `team.deleteTitle` | Delete {name}? |
64
+ | `team.describeHint` | A sentence or two is enough: its name, instructions and the rest are drafted for you to check. |
65
+ | `team.describePlaceholder` | Keeps the numbers straight for our clients: prices, costs and margins, with sources. |
60
66
  | `team.doesHint` | A line or two, for people, and for other agents deciding whom to ask. |
61
67
  | `team.doesPlaceholder` | Writes launch copy in our voice, and checks facts with the researcher. |
68
+ | `team.drafting` | Drafting… |
69
+ | `team.draftingWait` | Writing its instructions, a few seconds… |
70
+ | `team.draftIt` | Draft it |
62
71
  | `team.draftNote` | Written for you from what it should do: read them through, and change what you like. |
63
72
  | `team.edit` | Edit |
64
73
  | `team.editAgent` | Edit {name} |
@@ -67,6 +76,7 @@ Generated: `deno run -A packages/team/tests/words.ts`.
67
76
  | `team.emoji` | Emoji |
68
77
  | `team.fieldDoes` | What should it do? |
69
78
  | `team.fieldName` | Name |
79
+ | `team.fillMyself` | Fill it in myself |
70
80
  | `team.findAgent` | Find an agent |
71
81
  | `team.findAgentKnown` | Find an agent you know |
72
82
  | `team.findSpace` | Find a space |
@@ -93,6 +103,9 @@ Generated: `deno run -A packages/team/tests/words.ts`.
93
103
  | `team.keywordPersonal` | personal |
94
104
  | `team.keywordRename` | rename |
95
105
  | `team.keywordWork` | work |
106
+ | `team.kindHint` | Its model comes from the tier each chat runs on, for this kind of work. |
107
+ | `team.kindLabel` | Kind of work |
108
+ | `team.kindLike` | {kind} · like {agents} |
96
109
  | `team.knownIntro` | Agents you know, from the app and your spaces |
97
110
  | `team.listEnd` | {rest} and {last} |
98
111
  | `team.listJoin` | , |
@@ -140,7 +153,10 @@ Generated: `deno run -A packages/team/tests/words.ts`.
140
153
  | `team.notYourSpace` | This space isn't one of yours. |
141
154
  | `team.oneOfApps` | One of the app's agents |
142
155
  | `team.openPage` | Open its page |
156
+ | `team.orgForm` | A new agent for the org |
157
+ | `team.orgJoins` | It joins every space in the org, and every new one. |
143
158
  | `team.orgKey` | This org's key {hint} |
159
+ | `team.orgsTeam` | Your org's team |
144
160
  | `team.otherEmoji` | Other |
145
161
  | `team.paletteAgents` | Agents |
146
162
  | `team.paletteCreate` | Create |
@@ -157,6 +173,9 @@ Generated: `deno run -A packages/team/tests/words.ts`.
157
173
  | `team.readyToUse` | Ready to use |
158
174
  | `team.reasoning` | Reasoning |
159
175
  | `team.remove` | Remove |
176
+ | `team.removeButton` | Remove |
177
+ | `team.removeFromTeamMenu` | Remove from the team… |
178
+ | `team.removeTeamTitle` | Remove {name} from the team? |
160
179
  | `team.replace` | Replace |
161
180
  | `team.rewriteForMe` | Rewrite them for me |
162
181
  | `team.roleEditor` | Editor |
@@ -174,7 +193,14 @@ Generated: `deno run -A packages/team/tests/words.ts`.
174
193
  | `team.startFromShort` | Start from it |
175
194
  | `team.startingFrom` | Starting from {name}. |
176
195
  | `team.startNewFrom` | Start a new agent from {name}… |
196
+ | `team.teamAddBack` | You can add it back under Organization settings › Agents. |
197
+ | `team.teamDeleted` | It's deleted: its instructions are gone. |
198
+ | `team.teamLeaves` | {bold}, and won't join new ones. |
199
+ | `team.teamLeavesBold` | It leaves every space in the org |
200
+ | `team.teamSaidStays` | What it already said stays in its chats. |
177
201
  | `team.thinks` | Thinks |
202
+ | `team.tierModel` | Its model comes from the tier each chat runs on. Change the tiers' models under {place}. |
203
+ | `team.tierModelPlace` | Organization settings › Agents |
178
204
  | `team.tools` | Tools |
179
205
  | `team.toolsAll` | All |
180
206
  | `team.toolsChoose` | Choose |
@@ -198,3 +224,133 @@ Generated: `deno run -A packages/team/tests/words.ts`.
198
224
  | `team.youAreDefaultName` | Maya |
199
225
  | `team.youArePlaceholder` | You are {name}. You… |
200
226
  | `team.yourKey` | Your key |
227
+
228
+ ## tiers
229
+
230
+ | Key | English |
231
+ |---|---|
232
+ | `tiers.add` | Add |
233
+ | `tiers.addAgent` | Add an agent |
234
+ | `tiers.addAgentAbout` | It works in every space in {org}, and every new one. |
235
+ | `tiers.addAgentAboutMine` | It works in every space of yours, and every new one. |
236
+ | `tiers.addAgentTitle` | Add an agent to the team |
237
+ | `tiers.addBack` | Add back |
238
+ | `tiers.addBackTier` | Add back {tier} |
239
+ | `tiers.addFallback` | Add a fallback |
240
+ | `tiers.addKind` | Add a kind of work |
241
+ | `tiers.agentLine` | {model} · {kind} · on {tier} |
242
+ | `tiers.asOrg` | As the org: {tier} |
243
+ | `tiers.backToDefault` | Back to the default |
244
+ | `tiers.backToOrgDefault` | Back to the org's default |
245
+ | `tiers.backToOriginal` | Back to the original |
246
+ | `tiers.backToPlan` | Back to your plan's default |
247
+ | `tiers.badgeChanged` | Changed |
248
+ | `tiers.badgeDefault` | Default |
249
+ | `tiers.badgeOrgs` | Your org's |
250
+ | `tiers.badgePlan` | Plan's |
251
+ | `tiers.badgeYours` | Yours |
252
+ | `tiers.billing` | Billing |
253
+ | `tiers.budget` | budget |
254
+ | `tiers.byOrg` | the org's default |
255
+ | `tiers.byPerson` | your default |
256
+ | `tiers.byPlan` | your plan's default |
257
+ | `tiers.bySpace` | this space's default |
258
+ | `tiers.byThread` | chosen for this chat |
259
+ | `tiers.cancel` | Cancel |
260
+ | `tiers.capAny` | Any tier |
261
+ | `tiers.capLabel` | Members can choose up to |
262
+ | `tiers.capNote` | Owners and admins can always use any of them. |
263
+ | `tiers.changeAnyTime` | You can change it any time. |
264
+ | `tiers.chatRunsDefault` | This chat runs on its default. |
265
+ | `tiers.chatRunsOn` | This chat runs on {tier} from its next reply. |
266
+ | `tiers.copyOf` | {tier} copy |
267
+ | `tiers.createTier` | Create tier |
268
+ | `tiers.creditsMonth` | about {things} a month with {plan}'s {amount} |
269
+ | `tiers.creditsOnce` | about {things} with {plan}'s {amount} |
270
+ | `tiers.creditsSeat` | about {things} a month for each seat on {plan} |
271
+ | `tiers.customize` | Customize… |
272
+ | `tiers.customizeAbout` | Each kind of work's model, and what it falls back to when that one fails. Changes apply from each chat's next reply. |
273
+ | `tiers.customizeTitle` | Customize {tier} |
274
+ | `tiers.defaultForNew` | Default for new chats |
275
+ | `tiers.deleteTier` | Delete |
276
+ | `tiers.doneSaid` | New chats use {tier} from now on. |
277
+ | `tiers.duplicate` | Duplicate… |
278
+ | `tiers.edit` | Edit |
279
+ | `tiers.effortHigh` | high effort |
280
+ | `tiers.effortLow` | low effort |
281
+ | `tiers.effortMax` | max effort |
282
+ | `tiers.effortMedium` | medium effort |
283
+ | `tiers.effortMinimal` | minimal effort |
284
+ | `tiers.effortNone` | no reasoning |
285
+ | `tiers.effortOther` | {effort} effort |
286
+ | `tiers.effortXhigh` | extra-high effort |
287
+ | `tiers.emptyBody` | This app's agents each think with the model it gives them. |
288
+ | `tiers.emptyTitle` | No tiers to choose from |
289
+ | `tiers.fallbacks` | If it fails, then |
290
+ | `tiers.faster` | {tier} uses your credits about {times} faster than {cheapest}. |
291
+ | `tiers.fasterGoes` | That's {goes}. |
292
+ | `tiers.footMessage` | A typical message here, measured from how people use these agents: the one who answers often calls its model a few times, and others join some messages. |
293
+ | `tiers.footPrices` | At your org's prices; real ones vary. What agents spend stays within your {budget}. |
294
+ | `tiers.footReply` | A typical reply here: about 20,000 tokens read, most of them from the cache, and 1,000 written. |
295
+ | `tiers.forLabel` | What it's for |
296
+ | `tiers.forPlaceholder` | Strong judgment, quick checks. |
297
+ | `tiers.makeDefault` | Make it the default |
298
+ | `tiers.messages` | one: {count} message / other: {count} messages |
299
+ | `tiers.moveDown` | Move down |
300
+ | `tiers.moveUp` | Move up |
301
+ | `tiers.name` | Name |
302
+ | `tiers.namePlaceholder` | Balanced |
303
+ | `tiers.newChatsDefault` | Your new chats start on the default. |
304
+ | `tiers.newChatsOn` | Your new chats start on {tier}. |
305
+ | `tiers.newKind` | A new kind of work |
306
+ | `tiers.newKindPlaceholder` | Numbers |
307
+ | `tiers.newTier` | New tier |
308
+ | `tiers.newTierAbout` | Mix models your way: one for deciding, another for checking. |
309
+ | `tiers.newTierStarts` | It starts as {tier}: change the model for any kind of work. |
310
+ | `tiers.newTierTitle` | A new tier |
311
+ | `tiers.nobodyYet` | No agent does this yet |
312
+ | `tiers.noCredits` | {plan} gives this org no credits. |
313
+ | `tiers.noCreditsMore` | Choose a plan or add credits for your agents to start working. |
314
+ | `tiers.noFallback` | Nothing: if it fails, the reply fails. |
315
+ | `tiers.notOnTeam` | Not on your team |
316
+ | `tiers.nowMore` | Anyone can switch a chat's tier as they write, and spaces can set their own. |
317
+ | `tiers.nowOrg` | New chats use {tier}, your org's default. |
318
+ | `tiers.nowPlan` | New chats use {tier}, your plan's default. |
319
+ | `tiers.onlyRunners` | Only {org}'s owners and admins change these. You can switch a chat's tier as you write. |
320
+ | `tiers.onlyRunnersHere` | Only the org's owners and admins change these. You can switch a chat's tier as you write. |
321
+ | `tiers.onTier` | {model} on {tier} |
322
+ | `tiers.ownersChoose` | Your org's owners and admins choose this. |
323
+ | `tiers.perMessage` | a message |
324
+ | `tiers.perReply` | a reply |
325
+ | `tiers.pickCap` | Members can use up to {cap}. |
326
+ | `tiers.pickLabel` | Tier: {tier}, {by} |
327
+ | `tiers.pricedEach` | Priced as each model is |
328
+ | `tiers.providerChatgpt` | your ChatGPT plan |
329
+ | `tiers.recommended` | Recommended |
330
+ | `tiers.remove` | Remove |
331
+ | `tiers.removeBack` | You can add it back from this page. |
332
+ | `tiers.removeDeletes` | This deletes it. |
333
+ | `tiers.removeFromTeam` | Remove from the team |
334
+ | `tiers.removeSaid` | {name} leaves every space in {org} and won't join new ones. What it already said stays in its chats. |
335
+ | `tiers.removeSaidMine` | {name} leaves every space of yours and won't join new ones. What it already said stays in its chats. |
336
+ | `tiers.removeTitle` | Remove {name} from the team? |
337
+ | `tiers.replies` | one: {count} reply / other: {count} replies |
338
+ | `tiers.save` | Save |
339
+ | `tiers.spaceAsOrg` | As the org's default. |
340
+ | `tiers.spaceChosen` | Chosen for this space. The org's default is {tier}. |
341
+ | `tiers.spaceManagers` | This space's managers can change its default. |
342
+ | `tiers.spaceSelect` | This space's default tier |
343
+ | `tiers.spaceStartsOn` | New chats here start on {tier} |
344
+ | `tiers.spaceSwitch` | Anyone can switch a chat's tier as they write. |
345
+ | `tiers.startsFrom` | Starts from |
346
+ | `tiers.takeAway` | Take away |
347
+ | `tiers.takenAway` | Taken away: |
348
+ | `tiers.teamAbout` | Every space in {org} starts with these agents. Each does a kind of work, and the tier gives it its model. |
349
+ | `tiers.teamAboutMine` | Every space of yours starts with these agents. Each does a kind of work, and the tier gives it its model. |
350
+ | `tiers.teamTitle` | Your team |
351
+ | `tiers.then` | then {names} |
352
+ | `tiers.tierModels` | {tier}'s models |
353
+ | `tiers.tierMore` | {tier}: more |
354
+ | `tiers.tiersLabel` | Tiers |
355
+ | `tiers.underTenth` | under 0.1¢ |
356
+ | `tiers.undo` | Undo |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotz/team",
3
- "version": "1.0.0-rc.54",
3
+ "version": "1.0.0-rc.55",
4
4
  "description": "Agents people make, and the models an org's agents think with (tiers). A Copilotz plugin.",
5
5
  "keywords": [
6
6
  "copilotz",
@@ -53,7 +53,7 @@
53
53
  "dependencies": {},
54
54
  "peerDependencies": {
55
55
  "@types/react": "^19.3.0",
56
- "copilotz": "1.0.0-rc.54",
56
+ "copilotz": "1.0.0-rc.55",
57
57
  "react": "^19.3.1",
58
58
  "react-dom": "^19.3.1"
59
59
  },
@@ -1,4 +1,14 @@
1
1
  export declare const createAgentAction: import("copilotz").ActionDef;
2
2
  export declare const updateAgentAction: import("copilotz").ActionDef;
3
3
  export declare const deleteAgentAction: import("copilotz").ActionDef;
4
+ export declare const restoreAgentAction: import("copilotz").ActionDef;
5
+ export declare const resetAgentAction: import("copilotz").ActionDef;
4
6
  export declare const draftAgentAction: import("copilotz").ActionDef;
7
+ /**
8
+ * `agent.sketch` `{ asked, kinds? }`: a whole agent drafted from what a person
9
+ * says it should do, for them to read before making it: its name, emoji,
10
+ * what it does, instructions, and of the `kinds` of work given (`{ kind,
11
+ * title, agents? }`), the closest (`like`). One quick model call (the app's
12
+ * `cheap` alias when it has one); nothing is made.
13
+ */
14
+ export declare const sketchAgentAction: import("copilotz").ActionDef;
@@ -7,9 +7,20 @@
7
7
  * it should do, for a person to read before making it. Who may make or
8
8
  * change one where it belongs is the rules' business (with the access
9
9
  * plugin: those who manage that space).
10
+ *
11
+ * The org's team, by its owners and admins: one made for the org (`in: "*"`)
12
+ * joins every space in use, and new ones as they're made; it can work `like`
13
+ * one of the app's agents (that one's model, where the app chooses). One of
14
+ * the app's agents changed (`agent.update`) is the org's version of it, its
15
+ * model still the app's to choose; deleted (`agent.delete`), it's off the
16
+ * team: it leaves every space and joins no new one. `agent.restore` puts it
17
+ * back, as the org had it; `agent.reset` drops the org's changes, back to
18
+ * the app's, on the team.
10
19
  */
11
20
  import { defineAction, inPerson, invalid, people } from "copilotz";
12
- import { agentsOf, defaults, modelOf, SEND } from "copilotz/plugins/agents/contract";
21
+ import { agentsOf, defaults, modelOf, SEND, } from "copilotz/plugins/agents/contract";
22
+ import { must, ORG } from "copilotz/plugins/access/contract";
23
+ import { joinEverywhere, leaveEverywhere } from "../shared/everywhere.js";
13
24
  const forbidden = (agent) => Object.assign(new Error(`Only those who manage where "${agent}" belongs change it.`), {
14
25
  code: "forbidden",
15
26
  });
@@ -21,12 +32,53 @@ const fields = {
21
32
  effort: { type: "string" },
22
33
  tools: { type: "array", items: { type: "string" }, maxItems: 64 },
23
34
  icon: { type: "string", maxLength: 16 },
35
+ /** One of the app's agents whose model it takes, where the app chooses; "" for its own. */
36
+ like: { type: "string" },
24
37
  };
38
+ /** The model a ref tries first, as `"provider/model"` or an alias. */
39
+ function firstOf(ref) {
40
+ if (typeof ref === "string")
41
+ return ref;
42
+ if (Array.isArray(ref))
43
+ return firstOf(ref[0]);
44
+ return ref && typeof ref === "object" ? firstOf(ref.model) : undefined;
45
+ }
25
46
  /** The model agents are made with unless someone says: the app's first default agent's. */
26
47
  function usualModel(ctx) {
27
48
  const declared = agentsOf(ctx);
28
- const model = declared[defaults(declared)[0]]?.model;
29
- return typeof model === "string" ? model : undefined;
49
+ return firstOf(declared[defaults(declared)[0]]?.model);
50
+ }
51
+ /** A quick model for drafting: the app's `cheap` alias when it has one, else the usual one. */
52
+ function draftingModel(ctx) {
53
+ return ctx.resources.model?.cheap !== undefined
54
+ ? "cheap"
55
+ : usualModel(ctx);
56
+ }
57
+ /** Throws unless the caller runs the org: its team is its owners' and admins'. */
58
+ const runsTeam = (ctx) => must(ctx, "manage", ORG, "Only the org's owners and admins change its team.");
59
+ /** What one of the app's agents is shown as: its name, else its id with a capital. */
60
+ const nameOf = (id, agent) => agent.name ?? id[0].toUpperCase() + id.slice(1);
61
+ /** The org's version of one of the app's agents, as it starts: the app's, the org's from now on. */
62
+ async function versionOf(ctx, id, agent, more = {}) {
63
+ await ctx.db.collection("agent").insertOne({
64
+ _id: id,
65
+ name: nameOf(id, agent),
66
+ ...(agent.description ? { description: agent.description } : {}),
67
+ instructions: agent.instructions ?? "",
68
+ ...(agent.icon ? { icon: agent.icon } : {}),
69
+ in: ORG,
70
+ by: `${ctx.actor.kind}:${ctx.actor.id}`,
71
+ at: new Date().toISOString(),
72
+ ...more,
73
+ });
74
+ }
75
+ /** The kind of work it does, by name (the tiers say which there are; an unknown one is the first). */
76
+ function likeOf(_ctx, like) {
77
+ if (!like)
78
+ return undefined;
79
+ if (!/^[a-z0-9][a-z0-9-]{0,39}$/.test(like))
80
+ throw invalid(`"${like}" isn't a kind of work.`);
81
+ return like;
30
82
  }
31
83
  /** Throws unless every tool is the app's (or `send_message`) and the model can be called. */
32
84
  async function checked(ctx, given) {
@@ -73,8 +125,12 @@ export const createAgentAction = defineAction({
73
125
  const base = input.from ? agentsOf(ctx)[input.from] : undefined;
74
126
  if (input.from && !base)
75
127
  throw invalid(`No agent "${input.from}" to start from.`);
76
- const model = input.model ??
77
- (typeof base?.model === "string" ? base.model : undefined) ?? usualModel(ctx);
128
+ const like = likeOf(ctx, input.like);
129
+ if (input.in === ORG)
130
+ await runsTeam(ctx);
131
+ // With tiers, its model is its kind's in the tier in force; this one stands where none applies.
132
+ const model = input.model ?? firstOf(like ? agentsOf(ctx)[like]?.model : undefined) ??
133
+ firstOf(base?.model) ?? usualModel(ctx);
78
134
  if (!model)
79
135
  throw invalid("Say which model it uses.");
80
136
  const description = input.description ?? base?.description;
@@ -93,9 +149,13 @@ export const createAgentAction = defineAction({
93
149
  ...(tools ? { tools } : {}),
94
150
  ...(input.icon ? { icon: input.icon } : {}),
95
151
  ...(input.in ? { in: input.in } : {}),
152
+ ...(like ? { like } : {}),
96
153
  by: `${ctx.actor.kind}:${ctx.actor.id}`,
97
154
  at: new Date().toISOString(),
98
155
  });
156
+ // The org's own works in every space.
157
+ if (input.in === ORG)
158
+ await joinEverywhere(ctx, agent);
99
159
  return { agent };
100
160
  },
101
161
  });
@@ -110,11 +170,25 @@ export const updateAgentAction = defineAction({
110
170
  allow: inPerson,
111
171
  run: async (ctx, input) => {
112
172
  const { agent, ...given } = input;
113
- const found = await ctx.db.collection("agent").findOne({ _id: agent });
173
+ const app = agentsOf(ctx)[agent];
174
+ let found = await ctx.db.collection("agent").findOne({ _id: agent });
175
+ if (app) {
176
+ // One of the app's: the org changes its version of it; its model stays the app's to choose.
177
+ if (given.model || given.effort || given.like) {
178
+ throw invalid(`${nameOf(agent, app)}'s model is chosen with the org's tier.`);
179
+ }
180
+ await runsTeam(ctx);
181
+ if (!found) {
182
+ await versionOf(ctx, agent, app);
183
+ found = await ctx.db.collection("agent").findOne({ _id: agent });
184
+ }
185
+ }
114
186
  if (!found)
115
187
  throw invalid(`No agent "${agent}" to change.`);
188
+ if (given.like)
189
+ likeOf(ctx, given.like);
116
190
  await checked(ctx, { ...given, effort: given.effort ?? found.effort });
117
- const cleared = ["description", "icon", "effort"].filter((f) => given[f] === "");
191
+ const cleared = ["description", "icon", "effort", "like"].filter((f) => given[f] === "");
118
192
  const set = Object.fromEntries(Object.entries(given).filter(([field, value]) => value !== undefined && !cleared.includes(field)));
119
193
  const changed = await ctx.db.collection("agent").updateOne({ _id: agent }, {
120
194
  ...(Object.keys(set).length ? { $set: set } : {}),
@@ -135,15 +209,73 @@ export const deleteAgentAction = defineAction({
135
209
  },
136
210
  allow: inPerson,
137
211
  run: async (ctx, input) => {
212
+ const app = agentsOf(ctx)[input.agent];
138
213
  const known = await ctx.db.collection("agent").findOne({ _id: input.agent });
214
+ if (app) {
215
+ // One of the app's: off the org's team, as the org had it.
216
+ await runsTeam(ctx);
217
+ if (known) {
218
+ await ctx.db.collection("agent").updateOne({ _id: input.agent }, { $set: { off: true } });
219
+ }
220
+ else
221
+ await versionOf(ctx, input.agent, app, { off: true });
222
+ await leaveEverywhere(ctx, input.agent);
223
+ return { off: input.agent };
224
+ }
139
225
  if (!known)
140
226
  throw invalid(`No agent "${input.agent}" to remove.`);
227
+ if (known.in === ORG) {
228
+ await runsTeam(ctx);
229
+ await leaveEverywhere(ctx, input.agent);
230
+ }
141
231
  const gone = await ctx.db.collection("agent").deleteOne({ _id: input.agent });
142
232
  if (!gone.deletedCount)
143
233
  throw forbidden(input.agent);
144
234
  return { deleted: input.agent };
145
235
  },
146
236
  });
237
+ export const restoreAgentAction = defineAction({
238
+ description: "Puts one of the app's agents the org took off its team back on it",
239
+ input: {
240
+ type: "object",
241
+ properties: { agent: { type: "string" } },
242
+ required: ["agent"],
243
+ additionalProperties: false,
244
+ },
245
+ allow: inPerson,
246
+ run: async (ctx, input) => {
247
+ if (!agentsOf(ctx)[input.agent]) {
248
+ throw invalid(`"${input.agent}" isn't one of the app's agents.`);
249
+ }
250
+ await runsTeam(ctx);
251
+ await ctx.db.collection("agent").updateOne({ _id: input.agent }, { $unset: { off: "" } });
252
+ await joinEverywhere(ctx, input.agent);
253
+ return { agent: input.agent };
254
+ },
255
+ });
256
+ export const resetAgentAction = defineAction({
257
+ description: "Drops the org's changes to one of the app's agents: back to the app's, on the team",
258
+ input: {
259
+ type: "object",
260
+ properties: { agent: { type: "string" } },
261
+ required: ["agent"],
262
+ additionalProperties: false,
263
+ },
264
+ allow: inPerson,
265
+ run: async (ctx, input) => {
266
+ if (!agentsOf(ctx)[input.agent]) {
267
+ throw invalid(`"${input.agent}" isn't one of the app's agents.`);
268
+ }
269
+ await runsTeam(ctx);
270
+ const known = await ctx.db.collection("agent").findOne({ _id: input.agent });
271
+ if (!known)
272
+ return { agent: input.agent };
273
+ await ctx.db.collection("agent").deleteOne({ _id: input.agent });
274
+ if (known.off)
275
+ await joinEverywhere(ctx, input.agent);
276
+ return { agent: input.agent };
277
+ },
278
+ });
147
279
  const DRAFT = "You write the instructions an AI agent works by, in a team where people and " +
148
280
  "agents talk in conversations. From its name and what it should do, write its instructions " +
149
281
  'in the second person ("You are…"): who it is, what it does and doesn\'t, how it works and ' +
@@ -177,3 +309,90 @@ export const draftAgentAction = defineAction({
177
309
  return { instructions: text.trim() };
178
310
  },
179
311
  });
312
+ const SKETCH = "You design AI agents for a team where people and agents work together in " +
313
+ "conversations. From what a person says an agent should do, call make_agent once with: a " +
314
+ "short first name it's called by (one or two words, a person's name or a plain role, never " +
315
+ "the word 'agent' or 'bot'), one emoji, what it does in one or two plain sentences (for " +
316
+ "people and for other agents deciding whom to ask), its instructions in the second person " +
317
+ '("You are…": who it is, what it does and doesn\'t, how it works and answers; plain prose, ' +
318
+ "under 180 words), and the kind of work closest to it, from the list given. Write in the " +
319
+ "language the person wrote in.";
320
+ /**
321
+ * `agent.sketch` `{ asked, kinds? }`: a whole agent drafted from what a person
322
+ * says it should do, for them to read before making it: its name, emoji,
323
+ * what it does, instructions, and of the `kinds` of work given (`{ kind,
324
+ * title, agents? }`), the closest (`like`). One quick model call (the app's
325
+ * `cheap` alias when it has one); nothing is made.
326
+ */
327
+ export const sketchAgentAction = defineAction({
328
+ description: "Drafts a whole agent from what it should do",
329
+ input: {
330
+ type: "object",
331
+ properties: {
332
+ asked: { type: "string", minLength: 3, maxLength: 1000 },
333
+ kinds: {
334
+ type: "array",
335
+ maxItems: 20,
336
+ items: {
337
+ type: "object",
338
+ properties: {
339
+ kind: { type: "string" },
340
+ title: { type: "string" },
341
+ agents: { type: "array", items: { type: "string" } },
342
+ },
343
+ required: ["kind", "title"],
344
+ },
345
+ },
346
+ },
347
+ required: ["asked"],
348
+ additionalProperties: false,
349
+ },
350
+ allow: people,
351
+ run: async (ctx, input) => {
352
+ const model = draftingModel(ctx);
353
+ if (!model)
354
+ throw invalid("There's no model to draft it with.");
355
+ const kinds = (input.kinds ?? []);
356
+ const { text, toolCalls } = await ctx.call("llm.generate", {
357
+ model,
358
+ instructions: SKETCH,
359
+ messages: [{
360
+ role: "user",
361
+ text: `What it should do: ${input.asked}` +
362
+ (kinds.length
363
+ ? "\n\nKinds of work:\n" +
364
+ kinds.map((k) => `- ${k.kind}: ${k.title}${k.agents?.length ? ` (like ${k.agents.join(", ")})` : ""}`).join("\n")
365
+ : ""),
366
+ }],
367
+ tools: [{
368
+ name: "make_agent",
369
+ description: "The agent, drafted",
370
+ input: {
371
+ type: "object",
372
+ properties: {
373
+ name: { type: "string" },
374
+ icon: { type: "string" },
375
+ description: { type: "string" },
376
+ instructions: { type: "string" },
377
+ ...(kinds.length ? { kind: { type: "string", enum: kinds.map((k) => k.kind) } } : {}),
378
+ },
379
+ required: ["name", "icon", "description", "instructions"],
380
+ },
381
+ }],
382
+ tags: { purpose: "agent.draft" },
383
+ });
384
+ const made = toolCalls.find((c) => c.name === "make_agent")?.input;
385
+ if (!made?.name || !made.instructions) {
386
+ throw Object.assign(invalid("Couldn't draft it this time: try saying a bit more."), {
387
+ detail: { said: text.slice(0, 200) },
388
+ });
389
+ }
390
+ return {
391
+ name: made.name.trim().slice(0, 60),
392
+ icon: [...(made.icon ?? "").trim()].slice(0, 2).join(""),
393
+ description: (made.description ?? "").trim().slice(0, 500),
394
+ instructions: made.instructions.trim(),
395
+ ...(made.kind && kinds.some((k) => k.kind === made.kind) ? { like: made.kind } : {}),
396
+ };
397
+ },
398
+ });
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * `agent.define`: what agents people made are, by name, for chat (its
3
3
  * `agentSources` resource): those the asker meets (the rules say: where
4
- * they belong, or work in a space the asker reaches). Unrecorded, so
5
- * chat's queries and Views ask it too.
4
+ * they belong, or work in a space the asker reaches), and the org's
5
+ * versions of the app's agents (what it changed). Unrecorded, so chat's
6
+ * queries and Views ask it too.
6
7
  */
7
8
  import { defineAction } from "copilotz";
9
+ import { agentsOf } from "copilotz/plugins/agents/contract";
8
10
  import { definitionOf } from "../shared/definition.js";
9
11
  export const defineAgentsAction = defineAction({
10
12
  description: "What agents people made are, by name: those the asker meets",
@@ -19,9 +21,11 @@ export const defineAgentsAction = defineAction({
19
21
  const found = {};
20
22
  if (!input.names.length)
21
23
  return found;
24
+ const declared = agentsOf(ctx);
22
25
  const made = await ctx.db.collection("agent").find({ _id: { $in: input.names } });
26
+ // One of the app's: the org's version of it, over the app's (chat merges them).
23
27
  for (const doc of made)
24
- found[doc._id] = definitionOf(doc);
28
+ found[doc._id] = definitionOf(doc, declared[doc._id]);
25
29
  return found;
26
30
  },
27
31
  });