@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.
- package/LICENSE +21 -0
- package/README.md +50 -1
- package/WORDS.md +357 -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 +61 -3
- package/team/actions/agent.d.ts +14 -0
- package/team/actions/agent.js +401 -0
- package/team/actions/define.d.ts +1 -0
- package/team/actions/define.js +45 -0
- package/team/collections/agent.d.ts +170 -0
- package/team/collections/agent.js +126 -0
- package/team/contract.d.ts +11 -0
- package/team/contract.js +1 -0
- package/team/mod.d.ts +28 -0
- package/team/mod.js +64 -0
- package/team/resources/propose.d.ts +1 -0
- package/team/resources/propose.js +102 -0
- package/team/shared/definition.d.ts +3 -0
- package/team/shared/definition.js +11 -0
- package/team/shared/everywhere.d.ts +11 -0
- package/team/shared/everywhere.js +29 -0
- package/team/shared/limits.d.ts +17 -0
- package/team/shared/limits.js +17 -0
- package/team/views/web/agent-add.d.ts +14 -0
- package/team/views/web/agent-add.js +58 -0
- package/team/views/web/agent-describe.d.ts +38 -0
- package/team/views/web/agent-describe.js +44 -0
- package/team/views/web/agent-fields.d.ts +35 -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 +62 -0
- package/team/views/web/agent-new.d.ts +27 -0
- package/team/views/web/agent-new.js +150 -0
- package/team/views/web/agent-org.d.ts +12 -0
- package/team/views/web/agent-org.js +89 -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 +20 -0
- package/team/views/web/agent.js +310 -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 +27 -0
- package/team/views/web/model-pick.js +42 -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 +251 -0
- package/team/views/web/words.d.ts +5 -0
- package/team/views/web/words.js +239 -0
- package/team/web.d.ts +22 -0
- package/team/web.js +43 -0
- package/tiers/actions/choose.d.ts +7 -0
- package/tiers/actions/choose.js +315 -0
- package/tiers/actions/model.d.ts +1 -0
- package/tiers/actions/model.js +60 -0
- package/tiers/collections/choice.d.ts +57 -0
- package/tiers/collections/choice.js +79 -0
- package/tiers/collections/template.d.ts +76 -0
- package/tiers/collections/template.js +41 -0
- package/tiers/contract.d.ts +23 -0
- package/tiers/contract.js +1 -0
- package/tiers/mod.d.ts +72 -0
- package/tiers/mod.js +111 -0
- package/tiers/shared/plans.d.ts +65 -0
- package/tiers/shared/plans.js +91 -0
- package/tiers/shared/shown.d.ts +187 -0
- package/tiers/shared/shown.js +280 -0
- package/tiers/shared/tiers.d.ts +150 -0
- package/tiers/shared/tiers.js +170 -0
- package/tiers/views/web/composer.d.ts +14 -0
- package/tiers/views/web/composer.js +81 -0
- package/tiers/views/web/org.d.ts +61 -0
- package/tiers/views/web/org.js +289 -0
- package/tiers/views/web/say.d.ts +139 -0
- package/tiers/views/web/say.js +143 -0
- package/tiers/views/web/setup.d.ts +23 -0
- package/tiers/views/web/setup.js +80 -0
- package/tiers/views/web/space.d.ts +31 -0
- package/tiers/views/web/space.js +74 -0
- package/tiers/views/web/style.d.ts +7 -0
- package/tiers/views/web/style.js +191 -0
- package/tiers/views/web/team.d.ts +38 -0
- package/tiers/views/web/team.js +118 -0
- package/tiers/views/web/words.d.ts +48 -0
- package/tiers/views/web/words.js +122 -0
- package/tiers/web.d.ts +30 -0
- package/tiers/web.js +71 -0
- package/web.d.ts +14 -0
- package/web.js +14 -0
|
@@ -0,0 +1,126 @@
|
|
|
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 { defineCollection, people } from "pairz";
|
|
25
|
+
import { agentsOf, defaults, SEND } from "pairz/plugins/agents/contract";
|
|
26
|
+
import { definitionOf } from "../shared/definition.js";
|
|
27
|
+
import { ORG } from "pairz/plugins/access/contract";
|
|
28
|
+
const agentSchema = {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
/** What it's shown as ("Maya"); its `_id` is what it's called by. */
|
|
32
|
+
name: { type: "string" },
|
|
33
|
+
/** What it does, for people and for other agents deciding whom to message. */
|
|
34
|
+
description: { type: "string" },
|
|
35
|
+
instructions: { type: "string" },
|
|
36
|
+
/** `"provider/model"` or an alias (see the models plugin). */
|
|
37
|
+
model: { type: "string" },
|
|
38
|
+
effort: { type: "string" },
|
|
39
|
+
/** Names of `tools` resources it may call, and `send_message` to talk to others. */
|
|
40
|
+
tools: { type: "array", items: { type: "string" } },
|
|
41
|
+
/** An emoji it's shown with. */
|
|
42
|
+
icon: { type: "string" },
|
|
43
|
+
/** Where it was made: who manage that space change it; `*`, the org's own. */
|
|
44
|
+
in: { type: "string" },
|
|
45
|
+
/** One of the app's the org took off its team (on the org's version of it). */
|
|
46
|
+
off: { type: "boolean" },
|
|
47
|
+
/** One of the app's agents whose model it takes, where the app chooses models. */
|
|
48
|
+
like: { type: "string" },
|
|
49
|
+
/** Who made it: `person:ana`. */
|
|
50
|
+
by: { type: "string" },
|
|
51
|
+
at: { type: "string" },
|
|
52
|
+
},
|
|
53
|
+
// The org's version of one of the app's has no model of its own: the app's (and its tiers) choose.
|
|
54
|
+
required: ["name", "instructions", "at"],
|
|
55
|
+
};
|
|
56
|
+
export const agent = defineCollection({
|
|
57
|
+
schema: agentSchema,
|
|
58
|
+
queries: {
|
|
59
|
+
known: {
|
|
60
|
+
allow: people,
|
|
61
|
+
run: async (agents, _, ctx) => {
|
|
62
|
+
const known = { ...agentsOf(ctx) };
|
|
63
|
+
for (const doc of await agents.find({}, { sort: { name: 1 } })) {
|
|
64
|
+
known[doc._id] = definitionOf(doc);
|
|
65
|
+
}
|
|
66
|
+
return known;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
team: {
|
|
70
|
+
allow: people,
|
|
71
|
+
run: async (agents, _, ctx) => {
|
|
72
|
+
const declared = agentsOf(ctx);
|
|
73
|
+
const kept = await agents.find({ in: ORG });
|
|
74
|
+
const mine = new Map(kept.map((doc) => [doc._id, doc]));
|
|
75
|
+
const app = defaults(declared).map((name) => {
|
|
76
|
+
const doc = mine.get(name);
|
|
77
|
+
const shown = doc
|
|
78
|
+
? { ...declared[name], ...definitionOf(doc, declared[name]) }
|
|
79
|
+
: declared[name];
|
|
80
|
+
return {
|
|
81
|
+
id: name,
|
|
82
|
+
name: shown.name ?? name[0].toUpperCase() + name.slice(1),
|
|
83
|
+
...(shown.icon ? { icon: shown.icon } : {}),
|
|
84
|
+
...(shown.description ? { description: shown.description } : {}),
|
|
85
|
+
kind: doc ? "changed" : "app",
|
|
86
|
+
...(doc?.off ? { off: true } : {}),
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
const own = kept.filter((doc) => !declared[doc._id])
|
|
90
|
+
.sort((a, b) => a.at.localeCompare(b.at) || a._id.localeCompare(b._id))
|
|
91
|
+
.map((doc) => ({
|
|
92
|
+
id: doc._id,
|
|
93
|
+
name: doc.name,
|
|
94
|
+
...(doc.icon ? { icon: doc.icon } : {}),
|
|
95
|
+
...(doc.description ? { description: doc.description } : {}),
|
|
96
|
+
kind: "org",
|
|
97
|
+
...(doc.like ? { like: doc.like } : {}),
|
|
98
|
+
...(doc.model ? { model: doc.model } : {}),
|
|
99
|
+
}));
|
|
100
|
+
return { agents: [...app, ...own] };
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
options: {
|
|
104
|
+
allow: people,
|
|
105
|
+
run: async (_, __, ctx) => {
|
|
106
|
+
const tools = (ctx.resources.tools ?? {});
|
|
107
|
+
const declared = Object.values((ctx.resources.agents ?? {}));
|
|
108
|
+
const named = [
|
|
109
|
+
...new Set([
|
|
110
|
+
...declared.map((a) => a.model).filter((m) => typeof m === "string"),
|
|
111
|
+
...Object.keys(ctx.resources.model ?? {}),
|
|
112
|
+
]),
|
|
113
|
+
];
|
|
114
|
+
// Only those an agent can talk with (not a transcriber, an embedder).
|
|
115
|
+
const models = (await Promise.all(named.map((model) => ctx.call("models.check", { model, port: "llm" }).then(() => model, () => undefined)))).filter((model) => model !== undefined);
|
|
116
|
+
return {
|
|
117
|
+
tools: [
|
|
118
|
+
...Object.entries(tools).map(([name, t]) => ({ name, description: t.description })),
|
|
119
|
+
{ name: SEND, description: "Message other agents and people, and wait for replies" },
|
|
120
|
+
],
|
|
121
|
+
models,
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team plugin's contract: the shape of an agent people made, and of the
|
|
3
|
+
* hints its model picker takes on the web. The rest is reached by name: its
|
|
4
|
+
* collection `agent`, its queries (`agent.known`, `agent.options`), its
|
|
5
|
+
* Actions (`agent.create`, `agent.update`, `agent.delete`, `agent.draft`),
|
|
6
|
+
* and on the web its View `model.pick` (team-web's): the picker an agent's
|
|
7
|
+
* model is chosen with, for other front ends' pages.
|
|
8
|
+
*/
|
|
9
|
+
export type { AgentDoc } from "./collections/agent.js";
|
|
10
|
+
export type { ModelPick } from "./views/web/model-pick.js";
|
|
11
|
+
export { INSTRUCTIONS_LIMIT, type TeamSettings } from "./shared/limits.js";
|
package/team/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { INSTRUCTIONS_LIMIT } from "./shared/limits.js";
|
package/team/mod.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team: agents people make, beside those the app declares in code. A
|
|
3
|
+
* person makes one (`agent.create`: a name to call it by, what it does,
|
|
4
|
+
* instructions they can have written for them with `agent.draft`, a model,
|
|
5
|
+
* tools, an emoji), changes it (`agent.update`) or removes it
|
|
6
|
+
* (`agent.delete`). Chat meets them through its `agentSources` resource
|
|
7
|
+
* (`agent.define`): they work like any agent, where they work.
|
|
8
|
+
*
|
|
9
|
+
* With the access plugin, an agent belongs to the space it was made in
|
|
10
|
+
* (`in`): only that space's managers change it, and it's read wherever
|
|
11
|
+
* it's a member; adding it to a space is the spaces plugin's (`member.set`,
|
|
12
|
+
* by a manager who has met it). Without it, every agent is everyone's.
|
|
13
|
+
*
|
|
14
|
+
* The org's team (with the access plugin): the app's default agents, then
|
|
15
|
+
* those the org made for itself (`in: "*"`), which work in every space. Its
|
|
16
|
+
* owners and admins change the app's ones (the org's version of each), take
|
|
17
|
+
* them off the team (`agent.delete`) and back (`agent.restore`), or back to
|
|
18
|
+
* the app's (`agent.reset`). An agent proposes one (`propose_agent`, the
|
|
19
|
+
* tool an app gives agents it lets): its person sees it and says yes or no.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* plugins: [models, chat, ...access, team, app]
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { type Plugin } from "pairz";
|
|
26
|
+
export * from "./contract.js";
|
|
27
|
+
export declare const team: Plugin;
|
|
28
|
+
export default team;
|
package/team/mod.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team: agents people make, beside those the app declares in code. A
|
|
3
|
+
* person makes one (`agent.create`: a name to call it by, what it does,
|
|
4
|
+
* instructions they can have written for them with `agent.draft`, a model,
|
|
5
|
+
* tools, an emoji), changes it (`agent.update`) or removes it
|
|
6
|
+
* (`agent.delete`). Chat meets them through its `agentSources` resource
|
|
7
|
+
* (`agent.define`): they work like any agent, where they work.
|
|
8
|
+
*
|
|
9
|
+
* With the access plugin, an agent belongs to the space it was made in
|
|
10
|
+
* (`in`): only that space's managers change it, and it's read wherever
|
|
11
|
+
* it's a member; adding it to a space is the spaces plugin's (`member.set`,
|
|
12
|
+
* by a manager who has met it). Without it, every agent is everyone's.
|
|
13
|
+
*
|
|
14
|
+
* The org's team (with the access plugin): the app's default agents, then
|
|
15
|
+
* those the org made for itself (`in: "*"`), which work in every space. Its
|
|
16
|
+
* owners and admins change the app's ones (the org's version of each), take
|
|
17
|
+
* them off the team (`agent.delete`) and back (`agent.restore`), or back to
|
|
18
|
+
* the app's (`agent.reset`). An agent proposes one (`propose_agent`, the
|
|
19
|
+
* tool an app gives agents it lets): its person sees it and says yes or no.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* plugins: [models, chat, ...access, team, app]
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { definePlugin, failure } from "pairz";
|
|
26
|
+
import { createAgentAction, deleteAgentAction, draftAgentAction, resetAgentAction, restoreAgentAction, sketchAgentAction, updateAgentAction, } from "./actions/agent.js";
|
|
27
|
+
import { defineAgentsAction } from "./actions/define.js";
|
|
28
|
+
import { agent } from "./collections/agent.js";
|
|
29
|
+
import { proposeAgent } from "./resources/propose.js";
|
|
30
|
+
export * from "./contract.js";
|
|
31
|
+
export const team = definePlugin({
|
|
32
|
+
name: "team",
|
|
33
|
+
requires: ["chat"],
|
|
34
|
+
collections: { agent },
|
|
35
|
+
actions: {
|
|
36
|
+
"agent.create": createAgentAction,
|
|
37
|
+
"agent.update": updateAgentAction,
|
|
38
|
+
"agent.delete": deleteAgentAction,
|
|
39
|
+
"agent.draft": draftAgentAction,
|
|
40
|
+
"agent.sketch": sketchAgentAction,
|
|
41
|
+
"agent.restore": restoreAgentAction,
|
|
42
|
+
"agent.reset": resetAgentAction,
|
|
43
|
+
"agent.define": defineAgentsAction,
|
|
44
|
+
},
|
|
45
|
+
resources: {
|
|
46
|
+
// Its settings: how long an agent's instructions may be (shared/limits.ts).
|
|
47
|
+
team: {},
|
|
48
|
+
// Agents propose agents, for their person to approve (an app gives it to those it lets).
|
|
49
|
+
tools: { propose_agent: proposeAgent },
|
|
50
|
+
// Chat asks it what an agent not in the app's code is.
|
|
51
|
+
agentSources: { team: { action: "agent.define" } },
|
|
52
|
+
// With the access plugin: an agent belongs where it was made, its managers change it,
|
|
53
|
+
// and it's read where it works.
|
|
54
|
+
shared: { agent: { member: "agent", write: "manage" } },
|
|
55
|
+
},
|
|
56
|
+
// An agent is a member of spaces, with its tools and model: its Actions check what it's given.
|
|
57
|
+
guard: (_actor, { collection, access, direct }) => {
|
|
58
|
+
if (collection === "agent" && direct && access === "write") {
|
|
59
|
+
throw failure("forbidden", "Agents change through their Actions.", { public: true });
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
export default team;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const proposeAgent: import("pairz/plugins/agents/contract").Tool<Record<string, unknown>>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `propose_agent`: an agent proposes a new agent, for the person it works for
|
|
3
|
+
* to approve. It drafts the agent (a name, an emoji, what it does, its
|
|
4
|
+
* instructions, its kind of work) and where it would work: this space, or the
|
|
5
|
+
* whole org's team. The person is asked as chat asks for everything (its
|
|
6
|
+
* `ask`: a card in the conversation, Allow or No), and the turn waits. Only
|
|
7
|
+
* what the person could do themselves goes: a space they manage, the org's
|
|
8
|
+
* team if they run the org. Allowed, it's made (`agent.create`, as the app,
|
|
9
|
+
* on the person's yes) and works there at once; the agent can hand it the
|
|
10
|
+
* work. Never made without that yes.
|
|
11
|
+
*/
|
|
12
|
+
import { personOf } from "pairz";
|
|
13
|
+
import { ask, tool } from "pairz/plugins/agents/contract";
|
|
14
|
+
import { ORG } from "pairz/plugins/access/contract";
|
|
15
|
+
import { instructionsLimitOf } from "../shared/limits.js";
|
|
16
|
+
/** Whether the person runs the org, or manages the space: what they could do themselves. */
|
|
17
|
+
async function mayMake(ctx, person, where) {
|
|
18
|
+
const system = ctx.as();
|
|
19
|
+
if (where === ORG) {
|
|
20
|
+
const role = (await system.db.collection("member")
|
|
21
|
+
.findOne({ _id: `${ORG}|person:${person}` }))?.role;
|
|
22
|
+
return role === "owner" || role === "admin";
|
|
23
|
+
}
|
|
24
|
+
const seat = await system.db.collection("member")
|
|
25
|
+
.findOne({ _id: `${where}|person:${person}` });
|
|
26
|
+
return seat?.role === "manager";
|
|
27
|
+
}
|
|
28
|
+
export const proposeAgent = tool({
|
|
29
|
+
title: "Propose an agent",
|
|
30
|
+
description: "Propose a new agent for a job that keeps coming back, for the person you work " +
|
|
31
|
+
"for to approve (they see it and answer Allow or No; the turn waits). Give it a short name, " +
|
|
32
|
+
'an emoji, what it does in a sentence or two, its instructions in the second person ("You ' +
|
|
33
|
+
'are…"), the kind of work it does (one your context lists), and where it works: this ' +
|
|
34
|
+
"space, or the whole org's team. Use it when the person asks for one, or when a specialist " +
|
|
35
|
+
"would clearly do a recurring job better; never for a one-off.",
|
|
36
|
+
input: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
name: { type: "string", minLength: 1, maxLength: 60 },
|
|
40
|
+
icon: { type: "string", maxLength: 16 },
|
|
41
|
+
description: { type: "string", minLength: 1, maxLength: 500 },
|
|
42
|
+
instructions: { type: "string", minLength: 1 },
|
|
43
|
+
kind: { type: "string", maxLength: 40 },
|
|
44
|
+
where: { type: "string", enum: ["space", "org"] },
|
|
45
|
+
},
|
|
46
|
+
required: ["name", "description", "instructions"],
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
},
|
|
49
|
+
run: async (input, ctx) => {
|
|
50
|
+
const person = personOf(ctx.actor);
|
|
51
|
+
if (!person)
|
|
52
|
+
return "Only a person can approve a new agent: there's no one to ask here.";
|
|
53
|
+
const where = input.where === "org" ? ORG : ctx.in;
|
|
54
|
+
if (!where)
|
|
55
|
+
return "There's no space here to add it to: say where it should work.";
|
|
56
|
+
const limit = instructionsLimitOf(ctx.resources);
|
|
57
|
+
if (input.instructions.length > limit) {
|
|
58
|
+
return `Its instructions are too long: at most ${limit} characters. Make them shorter.`;
|
|
59
|
+
}
|
|
60
|
+
if (!await mayMake(ctx, person, where)) {
|
|
61
|
+
return where === ORG
|
|
62
|
+
? "Only the org's owners and admins add agents to its team: suggest it to them."
|
|
63
|
+
: "Only this space's managers add agents here: suggest it to one of them.";
|
|
64
|
+
}
|
|
65
|
+
const place = where === ORG ? "the org's team (every space)" : "this space";
|
|
66
|
+
const verdict = await ask(ctx, {
|
|
67
|
+
owner: person,
|
|
68
|
+
for: person,
|
|
69
|
+
agent: ctx.agent,
|
|
70
|
+
thread: ctx.thread,
|
|
71
|
+
...(ctx.in ? { in: ctx.in } : {}),
|
|
72
|
+
work: "agent",
|
|
73
|
+
on: `agent:${input.name.toLowerCase()}`,
|
|
74
|
+
detail: `${input.icon ? `${input.icon} ` : ""}${input.name}: ${input.description}`,
|
|
75
|
+
text: `add ${input.name} to ${place}`,
|
|
76
|
+
covers: `add agents to ${place}`,
|
|
77
|
+
answers: ["once", "deny"],
|
|
78
|
+
doing: `add a new agent, ${input.name}, to ${place}`,
|
|
79
|
+
question: `May I add a new agent, ${input.name}, to ${place}?\n${input.description}`,
|
|
80
|
+
});
|
|
81
|
+
if (verdict !== true)
|
|
82
|
+
return verdict;
|
|
83
|
+
// Their yes: made as the app, as they could have made it.
|
|
84
|
+
const system = ctx.as();
|
|
85
|
+
const { agent } = await system.call("agent.create", {
|
|
86
|
+
in: where,
|
|
87
|
+
name: input.name,
|
|
88
|
+
description: input.description,
|
|
89
|
+
instructions: input.instructions,
|
|
90
|
+
...(input.icon ? { icon: input.icon } : {}),
|
|
91
|
+
...(input.kind ? { like: input.kind } : {}),
|
|
92
|
+
});
|
|
93
|
+
if (where !== ORG) {
|
|
94
|
+
await system.call("member.set", {
|
|
95
|
+
space: where,
|
|
96
|
+
member: { kind: "agent", id: agent },
|
|
97
|
+
role: "editor",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return `Made @${agent}: it works in ${place} now. Hand it the work with send_message.`;
|
|
101
|
+
},
|
|
102
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const definitionOf = (doc, base) => ({
|
|
2
|
+
instructions: doc.instructions,
|
|
3
|
+
...(base ? {} : { model: doc.model ?? "" }),
|
|
4
|
+
...(doc.effort && !base ? { effort: doc.effort } : {}),
|
|
5
|
+
...(doc.tools ? { tools: doc.tools } : {}),
|
|
6
|
+
...(doc.description ? { description: doc.description } : {}),
|
|
7
|
+
...(doc.name !== doc._id || base ? { name: doc.name } : {}),
|
|
8
|
+
...(doc.icon ? { icon: doc.icon } : {}),
|
|
9
|
+
...(doc.in ? { in: doc.in } : {}),
|
|
10
|
+
...(doc.like ? { like: doc.like } : {}),
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The org's team works in every space: one joins the org's spaces in use
|
|
3
|
+
* (Personal ones too), as an editor, and leaves every space it works in, through
|
|
4
|
+
* the spaces plugin's Actions (`member.set`, `member.remove`), as the person
|
|
5
|
+
* running the org, who manages them all. Nothing without the spaces plugin.
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from "pairz";
|
|
8
|
+
/** The agent joins every space in use it isn't in. */
|
|
9
|
+
export declare function joinEverywhere(ctx: Context, agent: string): Promise<void>;
|
|
10
|
+
/** The agent leaves every space it works in. */
|
|
11
|
+
export declare function leaveEverywhere(ctx: Context, agent: string): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Where the agent works now: the spaces it's a member of. */
|
|
2
|
+
async function seatsOf(ctx, agent) {
|
|
3
|
+
const seats = await ctx.db.collection("member").find({ member: `agent:${agent}` });
|
|
4
|
+
return seats.filter((s) => !s.on).map((s) => s.space);
|
|
5
|
+
}
|
|
6
|
+
/** The agent joins every space in use it isn't in. */
|
|
7
|
+
export async function joinEverywhere(ctx, agent) {
|
|
8
|
+
if (!ctx.resources.roster)
|
|
9
|
+
return;
|
|
10
|
+
const seated = new Set(await seatsOf(ctx, agent));
|
|
11
|
+
const spaces = await ctx.db.collection("space").find({});
|
|
12
|
+
for (const space of spaces) {
|
|
13
|
+
if (space.archived || seated.has(space._id))
|
|
14
|
+
continue;
|
|
15
|
+
await ctx.call("member.set", {
|
|
16
|
+
space: space._id,
|
|
17
|
+
member: { kind: "agent", id: agent },
|
|
18
|
+
role: "editor",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The agent leaves every space it works in. */
|
|
23
|
+
export async function leaveEverywhere(ctx, agent) {
|
|
24
|
+
if (!ctx.resources.roster)
|
|
25
|
+
return;
|
|
26
|
+
for (const space of await seatsOf(ctx, agent)) {
|
|
27
|
+
await ctx.call("member.remove", { space, member: { kind: "agent", id: agent } });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long an agent's instructions may be: the app's setting (the `team` resource's
|
|
3
|
+
* `instructionsLimit`, in characters), else `INSTRUCTIONS_LIMIT`. Every turn sends them, so a
|
|
4
|
+
* limit bounds what one costs; an app whose agents say more raises it.
|
|
5
|
+
*/
|
|
6
|
+
import { type Resources } from "pairz";
|
|
7
|
+
/** The limit unless the app sets one: 100,000 characters. */
|
|
8
|
+
export declare const INSTRUCTIONS_LIMIT = 100000;
|
|
9
|
+
/** The app's settings for team (`resources.team`). */
|
|
10
|
+
export type TeamSettings = {
|
|
11
|
+
/** How long an agent's instructions may be, in characters (100,000). */
|
|
12
|
+
instructionsLimit?: number;
|
|
13
|
+
};
|
|
14
|
+
/** The limit in force. */
|
|
15
|
+
export declare const instructionsLimitOf: (resources: Resources) => number;
|
|
16
|
+
/** Throws `invalid`, naming the field, when `instructions` are longer than the limit. */
|
|
17
|
+
export declare function checkInstructions(resources: Resources, instructions: string | undefined): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long an agent's instructions may be: the app's setting (the `team` resource's
|
|
3
|
+
* `instructionsLimit`, in characters), else `INSTRUCTIONS_LIMIT`. Every turn sends them, so a
|
|
4
|
+
* limit bounds what one costs; an app whose agents say more raises it.
|
|
5
|
+
*/
|
|
6
|
+
import { failure } from "pairz";
|
|
7
|
+
/** The limit unless the app sets one: 100,000 characters. */
|
|
8
|
+
export const INSTRUCTIONS_LIMIT = 100_000;
|
|
9
|
+
/** The limit in force. */
|
|
10
|
+
export const instructionsLimitOf = (resources) => (resources.team ?? {}).instructionsLimit ?? INSTRUCTIONS_LIMIT;
|
|
11
|
+
/** Throws `invalid`, naming the field, when `instructions` are longer than the limit. */
|
|
12
|
+
export function checkInstructions(resources, instructions) {
|
|
13
|
+
const limit = instructionsLimitOf(resources);
|
|
14
|
+
if (instructions && instructions.length > limit) {
|
|
15
|
+
throw Object.assign(failure("invalid", `Instructions are at most ${limit.toLocaleString("en")} characters; these are ${instructions.length.toLocaleString("en")}.`, { public: true }), { detail: { field: "instructions" } });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adding an agent to a space (kind `agent.add`, item `{ _id }`, the space;
|
|
3
|
+
* hints `{ in, mode?, from? }`): the Agents tab of spaces' invite surface
|
|
4
|
+
* (the `spaceInvite` resource), and the command palette's "Add an agent"
|
|
5
|
+
* and "New agent". One the person has met that doesn't work there yet
|
|
6
|
+
* (`KnownAgents`), or a new one made there (`NewAgent`: at once when `mode`
|
|
7
|
+
* is "new", or when there's none to add; `from`, one of the app's agents to
|
|
8
|
+
* start from). For those who manage the space, while it's in use.
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactNode } from "react";
|
|
11
|
+
import type { ViewContext } from "pairz";
|
|
12
|
+
export declare const agentAddView: (item: {
|
|
13
|
+
_id?: string;
|
|
14
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Adding an agent to a space (kind `agent.add`, item `{ _id }`, the space;
|
|
4
|
+
* hints `{ in, mode?, from? }`): the Agents tab of spaces' invite surface
|
|
5
|
+
* (the `spaceInvite` resource), and the command palette's "Add an agent"
|
|
6
|
+
* and "New agent". One the person has met that doesn't work there yet
|
|
7
|
+
* (`KnownAgents`), or a new one made there (`NewAgent`: at once when `mode`
|
|
8
|
+
* is "new", or when there's none to add; `from`, one of the app's agents to
|
|
9
|
+
* start from). For those who manage the space, while it's in use.
|
|
10
|
+
*/
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import { Notice, Skeleton } from "pairz/web";
|
|
13
|
+
import { KnownAgents } from "./agent-known.js";
|
|
14
|
+
import { NewAgent } from "./agent-new.js";
|
|
15
|
+
import { manages, placeName } from "./places.js";
|
|
16
|
+
import { STYLE } from "./style.js";
|
|
17
|
+
import { sayText } from "pairz/web/words";
|
|
18
|
+
import { say } from "./words.js";
|
|
19
|
+
export const agentAddView = (item, ctx) => {
|
|
20
|
+
const id = item._id ?? (typeof ctx.hints.in === "string" ? ctx.hints.in : "");
|
|
21
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
22
|
+
const known = ctx.db.collection("agent").query("known", {}).value;
|
|
23
|
+
const here = ctx.db.collection("thread").query("agents", { in: id }).value;
|
|
24
|
+
const options = ctx.db.collection("agent").query("options", {}).value;
|
|
25
|
+
// Kinds of work, where tiers give agents their models (their front end says so: `agentKinds`).
|
|
26
|
+
const kindsAsked = !!ctx.resources.agentKinds?.query;
|
|
27
|
+
const tiers = kindsAsked
|
|
28
|
+
? ctx.db.collection("modelChoice").query("offered", {}).value
|
|
29
|
+
: undefined;
|
|
30
|
+
const style = _jsx("style", { href: "team-web", precedence: "pairz", children: STYLE });
|
|
31
|
+
if (!places || !known || !here || !options || (kindsAsked && !tiers)) {
|
|
32
|
+
return (_jsxs("div", { className: "agent-add", "aria-busy": "true", children: [style, _jsx(Skeleton, { height: 56, radius: "lg" }), _jsx(Skeleton, { height: 56, radius: "lg" })] }));
|
|
33
|
+
}
|
|
34
|
+
const space = places.find((p) => p._id === id);
|
|
35
|
+
if (!space || !manages(space) || space.archived) {
|
|
36
|
+
return (_jsx(Notice, { tone: "neutral", icon: "lock", children: !space
|
|
37
|
+
? say("notYourSpace")
|
|
38
|
+
: space.archived
|
|
39
|
+
? say("archivedSpace", { place: placeName(space) })
|
|
40
|
+
: say("managersAdd", { place: placeName(space) }) }));
|
|
41
|
+
}
|
|
42
|
+
// Those they've met that don't work here yet: the app's first, then by name.
|
|
43
|
+
const others = Object.entries(known).filter(([key]) => !here.here.includes(key))
|
|
44
|
+
.sort(([a, x], [b, y]) => Number(!!x.in) - Number(!!y.in) ||
|
|
45
|
+
(x.name || a).localeCompare(y.name || b, undefined, { sensitivity: "base" }));
|
|
46
|
+
const from = typeof ctx.hints.from === "string" ? ctx.hints.from : undefined;
|
|
47
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(AddAgent, { space: space, places: places, known: known, others: others, options: options, first: ctx.hints.mode === "new" || from || !others.length ? "new" : "known", from: from, kinds: tiers?.kinds.map((k) => ({
|
|
48
|
+
kind: k.kind,
|
|
49
|
+
title: sayText(k.title),
|
|
50
|
+
agents: k.agents.map((a) => a.name),
|
|
51
|
+
})), call: ctx.call })] }));
|
|
52
|
+
};
|
|
53
|
+
function AddAgent({ space, places, known, others, options, first, from, kinds, call }) {
|
|
54
|
+
const [mode, setMode] = useState(first);
|
|
55
|
+
return (_jsx("div", { className: "agent-add", children: mode === "known"
|
|
56
|
+
? (_jsx(KnownAgents, { space: space, agents: others, places: places, call: call, onNew: () => setMode("new") }))
|
|
57
|
+
: (_jsx(NewAgent, { space: space, known: known, options: options, call: call, from: from, kinds: kinds, onBack: others.length ? () => setMode("known") : undefined })) }));
|
|
58
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first step of making an agent: what it should do, in a sentence or two,
|
|
3
|
+
* and Draft it (`agent.sketch`: its name, emoji, what it does, instructions
|
|
4
|
+
* and kind of work, a moment on a real model, said so while it writes). Or
|
|
5
|
+
* fill it in by hand. And the kind-of-work field the form shows where tiers
|
|
6
|
+
* give agents their models.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from "react";
|
|
9
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
10
|
+
/** A kind of work, as tiers name it, with the app's agents that do it. */
|
|
11
|
+
export type KindOption = {
|
|
12
|
+
kind: string;
|
|
13
|
+
title: string;
|
|
14
|
+
agents?: string[];
|
|
15
|
+
};
|
|
16
|
+
/** What `agent.sketch` drafts. */
|
|
17
|
+
export type Sketch = {
|
|
18
|
+
name: string;
|
|
19
|
+
icon: string;
|
|
20
|
+
description: string;
|
|
21
|
+
instructions: string;
|
|
22
|
+
like?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function Describe({ kinds, call, onDraft, onSkip, placeholder }: {
|
|
25
|
+
kinds?: KindOption[];
|
|
26
|
+
call: Call;
|
|
27
|
+
onDraft(sketch: Sketch): void;
|
|
28
|
+
onSkip(): void;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
}): ReactNode;
|
|
31
|
+
/** The kind of work an agent does, where tiers give agents their models: in place of a model. */
|
|
32
|
+
export declare function KindField({ kinds, value, onChange, disabled }: {
|
|
33
|
+
kinds: KindOption[];
|
|
34
|
+
value: string;
|
|
35
|
+
onChange(kind: string): void;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
}): ReactNode;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The first step of making an agent: what it should do, in a sentence or two,
|
|
4
|
+
* and Draft it (`agent.sketch`: its name, emoji, what it does, instructions
|
|
5
|
+
* and kind of work, a moment on a real model, said so while it writes). Or
|
|
6
|
+
* fill it in by hand. And the kind-of-work field the form shows where tiers
|
|
7
|
+
* give agents their models.
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { Button, Field, message, Notice, Select, Spinner, Textarea } from "pairz/web";
|
|
11
|
+
import { say } from "./words.js";
|
|
12
|
+
export function Describe({ kinds, call, onDraft, onSkip, placeholder }) {
|
|
13
|
+
const [asked, setAsked] = useState("");
|
|
14
|
+
const [busy, setBusy] = useState(false);
|
|
15
|
+
const [error, setError] = useState();
|
|
16
|
+
const draft = async () => {
|
|
17
|
+
if (asked.trim().length < 3 || busy)
|
|
18
|
+
return;
|
|
19
|
+
setBusy(true);
|
|
20
|
+
setError(undefined);
|
|
21
|
+
try {
|
|
22
|
+
onDraft(await call("agent.sketch", {
|
|
23
|
+
asked: asked.trim(),
|
|
24
|
+
...(kinds?.length ? { kinds } : {}),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
setError(message(e));
|
|
29
|
+
setBusy(false);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return (_jsxs("div", { className: "agent-describe", children: [_jsx(Field, { label: say("fieldDoes"), hint: say("describeHint"), children: (control) => (_jsx(Textarea, { ...control, value: asked, rows: 3, autoGrow: true, autoFocus: true, disabled: busy, maxLength: 1000, placeholder: placeholder ?? say("describePlaceholder"), onChange: (e) => setAsked(e.target.value), onKeyDown: (e) => {
|
|
33
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey))
|
|
34
|
+
void draft();
|
|
35
|
+
} })) }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, _jsxs("div", { className: "agent-describe-end", children: [_jsx(Button, { variant: "ghost", size: "sm", onClick: onSkip, disabled: busy, children: say("fillMyself") }), _jsx(Button, { variant: "primary", icon: busy ? undefined : "sparkles", disabled: asked.trim().length < 3, loading: busy, onClick: () => void draft(), children: busy ? say("drafting") : say("draftIt") })] }), busy
|
|
36
|
+
? (_jsxs("p", { className: "agent-describe-wait", "aria-live": "polite", children: [_jsx(Spinner, { size: 12 }), " ", say("draftingWait")] }))
|
|
37
|
+
: null] }));
|
|
38
|
+
}
|
|
39
|
+
/** The kind of work an agent does, where tiers give agents their models: in place of a model. */
|
|
40
|
+
export function KindField({ kinds, value, onChange, disabled }) {
|
|
41
|
+
return (_jsx(Field, { label: say("kindLabel"), hint: say("kindHint"), children: (control) => (_jsx(Select, { ...control, value: value, disabled: disabled, onChange: (e) => onChange(e.target.value), children: kinds.map((k) => (_jsx("option", { value: k.kind, children: k.agents?.length
|
|
42
|
+
? say("kindLike", { kind: k.title, agents: k.agents.join(", ") })
|
|
43
|
+
: k.title }, k.kind))) })) }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an agent is, as a form: its emoji and name (and what it's called by,
|
|
3
|
+
* `@maya`), what it does, its instructions (written for the person from the
|
|
4
|
+
* two with `agent.draft` if they like: a moment on a real model, said so
|
|
5
|
+
* while it writes, and undone with a press), the model it thinks with, and
|
|
6
|
+
* the tools it may use (those it has, in a line; all of them to tick, on a
|
|
7
|
+
* press). Making an agent (`NewAgent`) and changing one (its page) show it;
|
|
8
|
+
* what's typed goes up as it changes (`onChange`, a patch).
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactNode } from "react";
|
|
11
|
+
import { type Options } from "./agents.js";
|
|
12
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
13
|
+
/** An agent being made or changed: its fields, as typed. */
|
|
14
|
+
export type Draft = {
|
|
15
|
+
name: string;
|
|
16
|
+
icon: string;
|
|
17
|
+
description: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
model: string;
|
|
20
|
+
tools: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare function AgentFields({ value, onChange, options, handle, call, autoFocus, disabled, model }: {
|
|
23
|
+
value: Draft;
|
|
24
|
+
/** What changed: the form merges it into what's there. */
|
|
25
|
+
onChange(patch: Partial<Draft>): void;
|
|
26
|
+
options: Options;
|
|
27
|
+
/** What it's called by: its id, or what a new one will be (none until it's named). */
|
|
28
|
+
handle: string;
|
|
29
|
+
call: Call;
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** What stands where the model is chosen: another field (an org's agent works like one), or none. */
|
|
33
|
+
model?: ReactNode;
|
|
34
|
+
}): ReactNode;
|
|
35
|
+
export {};
|