@pairz/team 0.0.1 → 1.0.0-rc.81

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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -1
  3. package/WORDS.md +357 -0
  4. package/contract.d.ts +8 -0
  5. package/contract.js +8 -0
  6. package/mod.d.ts +25 -0
  7. package/mod.js +25 -0
  8. package/package.json +61 -3
  9. package/team/actions/agent.d.ts +14 -0
  10. package/team/actions/agent.js +401 -0
  11. package/team/actions/define.d.ts +1 -0
  12. package/team/actions/define.js +45 -0
  13. package/team/collections/agent.d.ts +170 -0
  14. package/team/collections/agent.js +126 -0
  15. package/team/contract.d.ts +11 -0
  16. package/team/contract.js +1 -0
  17. package/team/mod.d.ts +28 -0
  18. package/team/mod.js +64 -0
  19. package/team/resources/propose.d.ts +1 -0
  20. package/team/resources/propose.js +102 -0
  21. package/team/shared/definition.d.ts +3 -0
  22. package/team/shared/definition.js +11 -0
  23. package/team/shared/everywhere.d.ts +11 -0
  24. package/team/shared/everywhere.js +29 -0
  25. package/team/shared/limits.d.ts +17 -0
  26. package/team/shared/limits.js +17 -0
  27. package/team/views/web/agent-add.d.ts +14 -0
  28. package/team/views/web/agent-add.js +58 -0
  29. package/team/views/web/agent-describe.d.ts +38 -0
  30. package/team/views/web/agent-describe.js +44 -0
  31. package/team/views/web/agent-fields.d.ts +35 -0
  32. package/team/views/web/agent-fields.js +88 -0
  33. package/team/views/web/agent-known.d.ts +22 -0
  34. package/team/views/web/agent-known.js +62 -0
  35. package/team/views/web/agent-new.d.ts +27 -0
  36. package/team/views/web/agent-new.js +150 -0
  37. package/team/views/web/agent-org.d.ts +12 -0
  38. package/team/views/web/agent-org.js +89 -0
  39. package/team/views/web/agent-palette.d.ts +19 -0
  40. package/team/views/web/agent-palette.js +203 -0
  41. package/team/views/web/agent-steps.d.ts +23 -0
  42. package/team/views/web/agent-steps.js +56 -0
  43. package/team/views/web/agent.d.ts +20 -0
  44. package/team/views/web/agent.js +310 -0
  45. package/team/views/web/agents.d.ts +48 -0
  46. package/team/views/web/agents.js +59 -0
  47. package/team/views/web/model-pick.d.ts +27 -0
  48. package/team/views/web/model-pick.js +42 -0
  49. package/team/views/web/model-picker.d.ts +57 -0
  50. package/team/views/web/model-picker.js +218 -0
  51. package/team/views/web/places.d.ts +24 -0
  52. package/team/views/web/places.js +10 -0
  53. package/team/views/web/style.d.ts +9 -0
  54. package/team/views/web/style.js +251 -0
  55. package/team/views/web/words.d.ts +5 -0
  56. package/team/views/web/words.js +239 -0
  57. package/team/web.d.ts +22 -0
  58. package/team/web.js +43 -0
  59. package/tiers/actions/choose.d.ts +7 -0
  60. package/tiers/actions/choose.js +315 -0
  61. package/tiers/actions/model.d.ts +1 -0
  62. package/tiers/actions/model.js +60 -0
  63. package/tiers/collections/choice.d.ts +57 -0
  64. package/tiers/collections/choice.js +79 -0
  65. package/tiers/collections/template.d.ts +76 -0
  66. package/tiers/collections/template.js +41 -0
  67. package/tiers/contract.d.ts +23 -0
  68. package/tiers/contract.js +1 -0
  69. package/tiers/mod.d.ts +72 -0
  70. package/tiers/mod.js +111 -0
  71. package/tiers/shared/plans.d.ts +65 -0
  72. package/tiers/shared/plans.js +91 -0
  73. package/tiers/shared/shown.d.ts +187 -0
  74. package/tiers/shared/shown.js +280 -0
  75. package/tiers/shared/tiers.d.ts +150 -0
  76. package/tiers/shared/tiers.js +170 -0
  77. package/tiers/views/web/composer.d.ts +14 -0
  78. package/tiers/views/web/composer.js +81 -0
  79. package/tiers/views/web/org.d.ts +61 -0
  80. package/tiers/views/web/org.js +289 -0
  81. package/tiers/views/web/say.d.ts +139 -0
  82. package/tiers/views/web/say.js +143 -0
  83. package/tiers/views/web/setup.d.ts +23 -0
  84. package/tiers/views/web/setup.js +80 -0
  85. package/tiers/views/web/space.d.ts +31 -0
  86. package/tiers/views/web/space.js +74 -0
  87. package/tiers/views/web/style.d.ts +7 -0
  88. package/tiers/views/web/style.js +191 -0
  89. package/tiers/views/web/team.d.ts +38 -0
  90. package/tiers/views/web/team.js +118 -0
  91. package/tiers/views/web/words.d.ts +48 -0
  92. package/tiers/views/web/words.js +122 -0
  93. package/tiers/web.d.ts +30 -0
  94. package/tiers/web.js +71 -0
  95. package/web.d.ts +14 -0
  96. package/web.js +14 -0
@@ -0,0 +1,401 @@
1
+ /**
2
+ * Agents people make: `agent.create` makes one where they say (`in`), named
3
+ * after what it's shown as (`Maya` is called `maya`; `maya-2` when that's
4
+ * taken), from the app's tools and models, or from one the app declares
5
+ * (`from`, to start from what it is); `agent.update` changes it,
6
+ * `agent.delete` removes it; `agent.draft` writes instructions from what
7
+ * it should do, for a person to read before making it. Who may make or
8
+ * change one where it belongs is the rules' business (with the access
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.
19
+ */
20
+ import { defineAction, inPerson, invalid, people } from "pairz";
21
+ import { agentsOf, defaults, modelOf, SEND, } from "pairz/plugins/agents/contract";
22
+ import { must, ORG } from "pairz/plugins/access/contract";
23
+ import { joinEverywhere, leaveEverywhere } from "../shared/everywhere.js";
24
+ import { checkInstructions } from "../shared/limits.js";
25
+ const forbidden = (agent) => Object.assign(new Error(`Only those who manage where "${agent}" belongs change it.`), {
26
+ code: "forbidden",
27
+ });
28
+ const fields = {
29
+ name: { type: "string", minLength: 1, maxLength: 60 },
30
+ description: { type: "string", maxLength: 500 },
31
+ // As long as the app lets them be (`team.instructionsLimit`: shared/limits.ts).
32
+ instructions: { type: "string" },
33
+ model: { type: "string", minLength: 1 },
34
+ effort: { type: "string" },
35
+ tools: { type: "array", items: { type: "string" }, maxItems: 64 },
36
+ icon: { type: "string", maxLength: 16 },
37
+ /** One of the app's agents whose model it takes, where the app chooses; "" for its own. */
38
+ like: { type: "string" },
39
+ };
40
+ /** The model a ref tries first, as `"provider/model"` or an alias. */
41
+ function firstOf(ref) {
42
+ if (typeof ref === "string")
43
+ return ref;
44
+ if (Array.isArray(ref))
45
+ return firstOf(ref[0]);
46
+ return ref && typeof ref === "object" ? firstOf(ref.model) : undefined;
47
+ }
48
+ /** The model agents are made with unless someone says: the app's first default agent's. */
49
+ function usualModel(ctx) {
50
+ const declared = agentsOf(ctx);
51
+ return firstOf(declared[defaults(declared)[0]]?.model);
52
+ }
53
+ /** A quick model for drafting: the app's `cheap` alias when it has one, else the usual one. */
54
+ function draftingModel(ctx) {
55
+ return ctx.resources.model?.cheap !== undefined
56
+ ? "cheap"
57
+ : usualModel(ctx);
58
+ }
59
+ /** Throws unless the caller runs the org: its team is its owners' and admins'. */
60
+ const runsTeam = (ctx) => must(ctx, "manage", ORG, "Only the org's owners and admins change its team.");
61
+ /** What one of the app's agents is shown as: its name, else its id with a capital. */
62
+ const nameOf = (id, agent) => agent.name ?? id[0].toUpperCase() + id.slice(1);
63
+ /** The org's version of one of the app's agents, as it starts: the app's, the org's from now on. */
64
+ async function versionOf(ctx, id, agent, more = {}) {
65
+ await ctx.db.collection("agent").insertOne({
66
+ _id: id,
67
+ name: nameOf(id, agent),
68
+ ...(agent.description ? { description: agent.description } : {}),
69
+ instructions: agent.instructions ?? "",
70
+ ...(agent.icon ? { icon: agent.icon } : {}),
71
+ in: ORG,
72
+ by: `${ctx.actor.kind}:${ctx.actor.id}`,
73
+ at: new Date().toISOString(),
74
+ ...more,
75
+ });
76
+ }
77
+ /** The kind of work it does, by name (the tiers say which there are; an unknown one is the first). */
78
+ function likeOf(_ctx, like) {
79
+ if (!like)
80
+ return undefined;
81
+ if (!/^[a-z0-9][a-z0-9-]{0,39}$/.test(like))
82
+ throw invalid(`"${like}" isn't a kind of work.`);
83
+ return like;
84
+ }
85
+ /** Throws unless every tool is the app's (or `send_message`) and the model can be called. */
86
+ async function checked(ctx, given) {
87
+ checkInstructions(ctx.resources, given.instructions);
88
+ const tools = (ctx.resources.tools ?? {});
89
+ const unknown = (given.tools ?? []).filter((name) => name !== SEND && !tools[name]);
90
+ if (unknown.length)
91
+ throw invalid(`No tool ${unknown.map((t) => `"${t}"`).join(", ")}.`);
92
+ if (given.model) {
93
+ await ctx.call("models.check", {
94
+ model: modelOf({ instructions: "", model: given.model, effort: given.effort }),
95
+ port: "llm",
96
+ }).catch((error) => {
97
+ throw invalid(error.message);
98
+ });
99
+ }
100
+ }
101
+ /** What `name` is called by: lowercase, dashes, unique among agents (`maya`, `maya-2`). */
102
+ async function handleFor(ctx, name) {
103
+ const base = name.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase()
104
+ .replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32) || "agent";
105
+ const declared = agentsOf(ctx);
106
+ const made = ctx.as().db.collection("agent");
107
+ for (let n = 1;; n++) {
108
+ const handle = n === 1 ? base : `${base}-${n}`;
109
+ if (!declared[handle] && !await made.findOne({ _id: handle }))
110
+ return handle;
111
+ }
112
+ }
113
+ export const createAgentAction = defineAction({
114
+ description: "Makes an agent, where you say; it's called by a name made from what it's shown as",
115
+ input: {
116
+ type: "object",
117
+ properties: {
118
+ in: { type: "string" },
119
+ /** One the app declares, to start from what it is. */
120
+ from: { type: "string" },
121
+ ...fields,
122
+ },
123
+ required: ["name"],
124
+ additionalProperties: false,
125
+ },
126
+ allow: inPerson,
127
+ run: async (ctx, input) => {
128
+ const base = input.from ? agentsOf(ctx)[input.from] : undefined;
129
+ if (input.from && !base)
130
+ throw invalid(`No agent "${input.from}" to start from.`);
131
+ const like = likeOf(ctx, input.like);
132
+ if (input.in === ORG)
133
+ await runsTeam(ctx);
134
+ // With tiers, its model is its kind's in the tier in force; this one stands where none applies.
135
+ const model = input.model ?? firstOf(like ? agentsOf(ctx)[like]?.model : undefined) ??
136
+ firstOf(base?.model) ?? usualModel(ctx);
137
+ if (!model)
138
+ throw invalid("Say which model it uses.");
139
+ const description = input.description ?? base?.description;
140
+ const tools = input.tools ?? base?.tools;
141
+ const effort = input.effort ?? base?.effort;
142
+ await checked(ctx, { ...input, model, tools, effort });
143
+ const agent = await handleFor(ctx, input.name);
144
+ await ctx.db.collection("agent").insertOne({
145
+ _id: agent,
146
+ name: input.name.trim(),
147
+ ...(description ? { description } : {}),
148
+ instructions: input.instructions ?? base?.instructions ??
149
+ `You are ${input.name.trim()}.${description ? ` ${description}` : ""}`,
150
+ model,
151
+ ...(effort ? { effort } : {}),
152
+ ...(tools ? { tools } : {}),
153
+ ...(input.icon ? { icon: input.icon } : {}),
154
+ ...(input.in ? { in: input.in } : {}),
155
+ ...(like ? { like } : {}),
156
+ by: `${ctx.actor.kind}:${ctx.actor.id}`,
157
+ at: new Date().toISOString(),
158
+ });
159
+ // The org's own works in every space.
160
+ if (input.in === ORG)
161
+ await joinEverywhere(ctx, agent);
162
+ return { agent };
163
+ },
164
+ });
165
+ export const updateAgentAction = defineAction({
166
+ description: "Changes an agent people made: what it's shown as, does, is told, uses",
167
+ input: {
168
+ type: "object",
169
+ properties: { agent: { type: "string" }, ...fields },
170
+ required: ["agent"],
171
+ additionalProperties: false,
172
+ },
173
+ allow: inPerson,
174
+ run: async (ctx, input) => {
175
+ const { agent, ...given } = input;
176
+ const app = agentsOf(ctx)[agent];
177
+ let found = await ctx.db.collection("agent").findOne({ _id: agent });
178
+ if (app) {
179
+ // One of the app's: the org changes its version of it; its model stays the app's to choose.
180
+ if (given.model || given.effort || given.like) {
181
+ throw invalid(`${nameOf(agent, app)}'s model is chosen with the org's tier.`);
182
+ }
183
+ await runsTeam(ctx);
184
+ if (!found) {
185
+ await versionOf(ctx, agent, app);
186
+ found = await ctx.db.collection("agent").findOne({ _id: agent });
187
+ }
188
+ }
189
+ if (!found)
190
+ throw invalid(`No agent "${agent}" to change.`);
191
+ if (given.like)
192
+ likeOf(ctx, given.like);
193
+ await checked(ctx, { ...given, effort: given.effort ?? found.effort });
194
+ const cleared = ["description", "icon", "effort", "like"].filter((f) => given[f] === "");
195
+ const set = Object.fromEntries(Object.entries(given).filter(([field, value]) => value !== undefined && !cleared.includes(field)));
196
+ const changed = await ctx.db.collection("agent").updateOne({ _id: agent }, {
197
+ ...(Object.keys(set).length ? { $set: set } : {}),
198
+ ...(cleared.length ? { $unset: Object.fromEntries(cleared.map((f) => [f, ""])) } : {}),
199
+ });
200
+ if (!changed.matchedCount)
201
+ throw forbidden(agent);
202
+ return { agent };
203
+ },
204
+ });
205
+ export const deleteAgentAction = defineAction({
206
+ description: "Removes an agent people made, from everywhere it works",
207
+ input: {
208
+ type: "object",
209
+ properties: { agent: { type: "string" } },
210
+ required: ["agent"],
211
+ additionalProperties: false,
212
+ },
213
+ allow: inPerson,
214
+ run: async (ctx, input) => {
215
+ const app = agentsOf(ctx)[input.agent];
216
+ const known = await ctx.db.collection("agent").findOne({ _id: input.agent });
217
+ if (app) {
218
+ // One of the app's: off the org's team, as the org had it.
219
+ await runsTeam(ctx);
220
+ if (known) {
221
+ await ctx.db.collection("agent").updateOne({ _id: input.agent }, { $set: { off: true } });
222
+ }
223
+ else
224
+ await versionOf(ctx, input.agent, app, { off: true });
225
+ await leaveEverywhere(ctx, input.agent);
226
+ return { off: input.agent };
227
+ }
228
+ if (!known)
229
+ throw invalid(`No agent "${input.agent}" to remove.`);
230
+ if (known.in === ORG) {
231
+ await runsTeam(ctx);
232
+ await leaveEverywhere(ctx, input.agent);
233
+ }
234
+ const gone = await ctx.db.collection("agent").deleteOne({ _id: input.agent });
235
+ if (!gone.deletedCount)
236
+ throw forbidden(input.agent);
237
+ return { deleted: input.agent };
238
+ },
239
+ });
240
+ export const restoreAgentAction = defineAction({
241
+ description: "Puts one of the app's agents the org took off its team back on it",
242
+ input: {
243
+ type: "object",
244
+ properties: { agent: { type: "string" } },
245
+ required: ["agent"],
246
+ additionalProperties: false,
247
+ },
248
+ allow: inPerson,
249
+ run: async (ctx, input) => {
250
+ if (!agentsOf(ctx)[input.agent]) {
251
+ throw invalid(`"${input.agent}" isn't one of the app's agents.`);
252
+ }
253
+ await runsTeam(ctx);
254
+ await ctx.db.collection("agent").updateOne({ _id: input.agent }, { $unset: { off: "" } });
255
+ await joinEverywhere(ctx, input.agent);
256
+ return { agent: input.agent };
257
+ },
258
+ });
259
+ export const resetAgentAction = defineAction({
260
+ description: "Drops the org's changes to one of the app's agents: back to the app's, on the team",
261
+ input: {
262
+ type: "object",
263
+ properties: { agent: { type: "string" } },
264
+ required: ["agent"],
265
+ additionalProperties: false,
266
+ },
267
+ allow: inPerson,
268
+ run: async (ctx, input) => {
269
+ if (!agentsOf(ctx)[input.agent]) {
270
+ throw invalid(`"${input.agent}" isn't one of the app's agents.`);
271
+ }
272
+ await runsTeam(ctx);
273
+ const known = await ctx.db.collection("agent").findOne({ _id: input.agent });
274
+ if (!known)
275
+ return { agent: input.agent };
276
+ await ctx.db.collection("agent").deleteOne({ _id: input.agent });
277
+ if (known.off)
278
+ await joinEverywhere(ctx, input.agent);
279
+ return { agent: input.agent };
280
+ },
281
+ });
282
+ const DRAFT = "You write the instructions an AI agent works by, in a team where people and " +
283
+ "agents talk in conversations. From its name and what it should do, write its instructions " +
284
+ 'in the second person ("You are…"): who it is, what it does and doesn\'t, how it works and ' +
285
+ "answers. Plain prose, under 200 words. Reply with the instructions alone.";
286
+ export const draftAgentAction = defineAction({
287
+ description: "Writes instructions for an agent from its name and what it should do",
288
+ input: {
289
+ type: "object",
290
+ properties: {
291
+ name: fields.name,
292
+ description: { type: "string", minLength: 1, maxLength: 500 },
293
+ model: fields.model,
294
+ },
295
+ required: ["name", "description"],
296
+ additionalProperties: false,
297
+ },
298
+ allow: people,
299
+ run: async (ctx, input) => {
300
+ const model = input.model ?? usualModel(ctx);
301
+ if (!model)
302
+ throw invalid("Say which model writes it.");
303
+ const { text } = await ctx.call("llm.generate", {
304
+ model,
305
+ instructions: DRAFT,
306
+ messages: [{
307
+ role: "user",
308
+ text: `Name: ${input.name}\nWhat it should do: ${input.description}`,
309
+ }],
310
+ tags: { purpose: "agent.draft" },
311
+ });
312
+ return { instructions: text.trim() };
313
+ },
314
+ });
315
+ const SKETCH = "You design AI agents for a team where people and agents work together in " +
316
+ "conversations. From what a person says an agent should do, call make_agent once with: a " +
317
+ "short first name it's called by (one or two words, a person's name or a plain role, never " +
318
+ "the word 'agent' or 'bot'), one emoji, what it does in one or two plain sentences (for " +
319
+ "people and for other agents deciding whom to ask), its instructions in the second person " +
320
+ '("You are…": who it is, what it does and doesn\'t, how it works and answers; plain prose, ' +
321
+ "under 180 words), and the kind of work closest to it, from the list given. Write in the " +
322
+ "language the person wrote in.";
323
+ /**
324
+ * `agent.sketch` `{ asked, kinds? }`: a whole agent drafted from what a person
325
+ * says it should do, for them to read before making it: its name, emoji,
326
+ * what it does, instructions, and of the `kinds` of work given (`{ kind,
327
+ * title, agents? }`), the closest (`like`). One quick model call (the app's
328
+ * `cheap` alias when it has one); nothing is made.
329
+ */
330
+ export const sketchAgentAction = defineAction({
331
+ description: "Drafts a whole agent from what it should do",
332
+ input: {
333
+ type: "object",
334
+ properties: {
335
+ asked: { type: "string", minLength: 3, maxLength: 1000 },
336
+ kinds: {
337
+ type: "array",
338
+ maxItems: 20,
339
+ items: {
340
+ type: "object",
341
+ properties: {
342
+ kind: { type: "string" },
343
+ title: { type: "string" },
344
+ agents: { type: "array", items: { type: "string" } },
345
+ },
346
+ required: ["kind", "title"],
347
+ },
348
+ },
349
+ },
350
+ required: ["asked"],
351
+ additionalProperties: false,
352
+ },
353
+ allow: people,
354
+ run: async (ctx, input) => {
355
+ const model = draftingModel(ctx);
356
+ if (!model)
357
+ throw invalid("There's no model to draft it with.");
358
+ const kinds = (input.kinds ?? []);
359
+ const { text, toolCalls } = await ctx.call("llm.generate", {
360
+ model,
361
+ instructions: SKETCH,
362
+ messages: [{
363
+ role: "user",
364
+ text: `What it should do: ${input.asked}` +
365
+ (kinds.length
366
+ ? "\n\nKinds of work:\n" +
367
+ kinds.map((k) => `- ${k.kind}: ${k.title}${k.agents?.length ? ` (like ${k.agents.join(", ")})` : ""}`).join("\n")
368
+ : ""),
369
+ }],
370
+ tools: [{
371
+ name: "make_agent",
372
+ description: "The agent, drafted",
373
+ input: {
374
+ type: "object",
375
+ properties: {
376
+ name: { type: "string" },
377
+ icon: { type: "string" },
378
+ description: { type: "string" },
379
+ instructions: { type: "string" },
380
+ ...(kinds.length ? { kind: { type: "string", enum: kinds.map((k) => k.kind) } } : {}),
381
+ },
382
+ required: ["name", "icon", "description", "instructions"],
383
+ },
384
+ }],
385
+ tags: { purpose: "agent.draft" },
386
+ });
387
+ const made = toolCalls.find((c) => c.name === "make_agent")?.input;
388
+ if (!made?.name || !made.instructions) {
389
+ throw Object.assign(invalid("Couldn't draft it this time: try saying a bit more."), {
390
+ detail: { said: text.slice(0, 200) },
391
+ });
392
+ }
393
+ return {
394
+ name: made.name.trim().slice(0, 60),
395
+ icon: [...(made.icon ?? "").trim()].slice(0, 2).join(""),
396
+ description: (made.description ?? "").trim().slice(0, 500),
397
+ instructions: made.instructions.trim(),
398
+ ...(made.kind && kinds.some((k) => k.kind === made.kind) ? { like: made.kind } : {}),
399
+ };
400
+ },
401
+ });
@@ -0,0 +1 @@
1
+ export declare const defineAgentsAction: import("pairz").ActionDef;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `agent.define`: what agents people made are, by name, for chat (its
3
+ * `agentSources` resource): those the asker meets (the rules say: where
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), whoever asks: an app's
6
+ * agent is the org's version of it for everyone it talks with, contacts
7
+ * too. Unrecorded, so chat's queries and Views ask it too; there, as a read,
8
+ * it reads only what the asker reads, and a turn gives its prompt the agent
9
+ * it found (chat's turn).
10
+ */
11
+ import { defineAction } from "pairz";
12
+ import { agentsOf } from "pairz/plugins/agents/contract";
13
+ import { ORG } from "pairz/plugins/access/contract";
14
+ import { definitionOf } from "../shared/definition.js";
15
+ export const defineAgentsAction = defineAction({
16
+ description: "What agents people made are, by name: those the asker meets",
17
+ input: {
18
+ type: "object",
19
+ properties: { names: { type: "array", items: { type: "string" } } },
20
+ required: ["names"],
21
+ additionalProperties: false,
22
+ },
23
+ record: false,
24
+ run: async (ctx, input) => {
25
+ const found = {};
26
+ if (!input.names.length)
27
+ return found;
28
+ const declared = agentsOf(ctx);
29
+ const app = input.names.filter((name) => declared[name]);
30
+ const others = input.names.filter((name) => !declared[name]);
31
+ // One of the app's: the org's version of it, over the app's (chat merges them). It's that
32
+ // agent for everyone it talks with, a contact too, so it's read as the system; who may
33
+ // change it is the rules' (agent.update).
34
+ const versions = app.length
35
+ ? await ctx.as().db.collection("agent").find({ _id: { $in: app }, in: ORG })
36
+ : [];
37
+ // One people made: as the asker meets it (the rules).
38
+ const made = others.length
39
+ ? await ctx.db.collection("agent").find({ _id: { $in: others } })
40
+ : [];
41
+ for (const doc of [...versions, ...made])
42
+ found[doc._id] = definitionOf(doc, declared[doc._id]);
43
+ return found;
44
+ },
45
+ });
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Agents people make, beside those the app declares (chat's `agents`
3
+ * resource): a name to call it by (`_id`, as `@maya`), what it's shown as,
4
+ * what it does, its instructions, model and tools. It belongs where it was
5
+ * made (`in`, a space with the access plugin): who manage that space change
6
+ * it; others meet it where it works.
7
+ *
8
+ * The org's team: one that belongs to the org itself (`in: "*"`) is the
9
+ * org's own, its owners and admins change it, and it works in every space;
10
+ * one with the name of one of the app's agents is the org's version of it
11
+ * (what the org changed of it), and `off` there, the org took it off its
12
+ * team. One the org made can work `like` one of the app's agents: it takes
13
+ * that one's model, where the app chooses models (tiers).
14
+ *
15
+ * Its queries:
16
+ *
17
+ * - `known`: every agent the asker has met, to add one where they work:
18
+ * the app's, and those people made that belong to or work in a space
19
+ * they reach (the rules say);
20
+ * - `options`: what an agent can be made with: the app's tools and models;
21
+ * - `team`: the org's team, for its page: the app's agents (as the org has
22
+ * them: as they are, changed, or taken off), then the org's own.
23
+ */
24
+ import { type Infer } from "pairz";
25
+ declare const agentSchema: {
26
+ readonly type: "object";
27
+ readonly properties: {
28
+ /** What it's shown as ("Maya"); its `_id` is what it's called by. */
29
+ readonly name: {
30
+ readonly type: "string";
31
+ };
32
+ /** What it does, for people and for other agents deciding whom to message. */
33
+ readonly description: {
34
+ readonly type: "string";
35
+ };
36
+ readonly instructions: {
37
+ readonly type: "string";
38
+ };
39
+ /** `"provider/model"` or an alias (see the models plugin). */
40
+ readonly model: {
41
+ readonly type: "string";
42
+ };
43
+ readonly effort: {
44
+ readonly type: "string";
45
+ };
46
+ /** Names of `tools` resources it may call, and `send_message` to talk to others. */
47
+ readonly tools: {
48
+ readonly type: "array";
49
+ readonly items: {
50
+ readonly type: "string";
51
+ };
52
+ };
53
+ /** An emoji it's shown with. */
54
+ readonly icon: {
55
+ readonly type: "string";
56
+ };
57
+ /** Where it was made: who manage that space change it; `*`, the org's own. */
58
+ readonly in: {
59
+ readonly type: "string";
60
+ };
61
+ /** One of the app's the org took off its team (on the org's version of it). */
62
+ readonly off: {
63
+ readonly type: "boolean";
64
+ };
65
+ /** One of the app's agents whose model it takes, where the app chooses models. */
66
+ readonly like: {
67
+ readonly type: "string";
68
+ };
69
+ /** Who made it: `person:ana`. */
70
+ readonly by: {
71
+ readonly type: "string";
72
+ };
73
+ readonly at: {
74
+ readonly type: "string";
75
+ };
76
+ };
77
+ readonly required: readonly ["name", "instructions", "at"];
78
+ };
79
+ export declare const agent: Omit<import("pairz").CollectionDef, "schema" | "queries"> & {
80
+ queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
81
+ [x: string]: unknown;
82
+ description?: string | undefined;
83
+ model?: string | undefined;
84
+ effort?: string | undefined;
85
+ tools?: string[] | undefined;
86
+ icon?: string | undefined;
87
+ in?: string | undefined;
88
+ off?: boolean | undefined;
89
+ like?: string | undefined;
90
+ by?: string | undefined;
91
+ name: string;
92
+ instructions: string;
93
+ at: string;
94
+ }>>> | undefined;
95
+ } & {
96
+ schema: {
97
+ readonly type: "object";
98
+ readonly properties: {
99
+ /** What it's shown as ("Maya"); its `_id` is what it's called by. */
100
+ readonly name: {
101
+ readonly type: "string";
102
+ };
103
+ /** What it does, for people and for other agents deciding whom to message. */
104
+ readonly description: {
105
+ readonly type: "string";
106
+ };
107
+ readonly instructions: {
108
+ readonly type: "string";
109
+ };
110
+ /** `"provider/model"` or an alias (see the models plugin). */
111
+ readonly model: {
112
+ readonly type: "string";
113
+ };
114
+ readonly effort: {
115
+ readonly type: "string";
116
+ };
117
+ /** Names of `tools` resources it may call, and `send_message` to talk to others. */
118
+ readonly tools: {
119
+ readonly type: "array";
120
+ readonly items: {
121
+ readonly type: "string";
122
+ };
123
+ };
124
+ /** An emoji it's shown with. */
125
+ readonly icon: {
126
+ readonly type: "string";
127
+ };
128
+ /** Where it was made: who manage that space change it; `*`, the org's own. */
129
+ readonly in: {
130
+ readonly type: "string";
131
+ };
132
+ /** One of the app's the org took off its team (on the org's version of it). */
133
+ readonly off: {
134
+ readonly type: "boolean";
135
+ };
136
+ /** One of the app's agents whose model it takes, where the app chooses models. */
137
+ readonly like: {
138
+ readonly type: "string";
139
+ };
140
+ /** Who made it: `person:ana`. */
141
+ readonly by: {
142
+ readonly type: "string";
143
+ };
144
+ readonly at: {
145
+ readonly type: "string";
146
+ };
147
+ };
148
+ readonly required: readonly ["name", "instructions", "at"];
149
+ };
150
+ };
151
+ export type AgentDoc = Infer<typeof agentSchema> & {
152
+ _id: string;
153
+ };
154
+ /**
155
+ * An agent of the org's team, as its page shows it: one of the app's as it is
156
+ * (`app`) or as the org changed it (`changed`, `off` when it took it off its
157
+ * team), or one the org made (`org`), with the app's agent it works `like` or
158
+ * its own `model`.
159
+ */
160
+ export type TeamAgent = {
161
+ id: string;
162
+ name: string;
163
+ icon?: string;
164
+ description?: string;
165
+ kind: "app" | "changed" | "org";
166
+ off?: true;
167
+ like?: string;
168
+ model?: string;
169
+ };
170
+ export {};