@pairz/team 0.0.0-stage → 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 +51 -2
- 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 +63 -4
- 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,203 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Avatar, go } from "pairz/web";
|
|
3
|
+
import { deleteStep, spaceStep } from "./agent-steps.js";
|
|
4
|
+
import { agentPath, shownAs } from "./agents.js";
|
|
5
|
+
import { managed, manages, placeName, placePath } from "./places.js";
|
|
6
|
+
import { say } from "./words.js";
|
|
7
|
+
/** How many agents show with nothing typed, and while searching. */
|
|
8
|
+
const SHOWN = { idle: 4, searching: 8 };
|
|
9
|
+
export const agentPaletteView = (_, ctx) => {
|
|
10
|
+
const searching = !!String(ctx.hints.search ?? "").trim();
|
|
11
|
+
const space = typeof ctx.hints.in === "string" ? ctx.hints.in : undefined;
|
|
12
|
+
const page = (ctx.hints.page ?? {});
|
|
13
|
+
const open = page.kind === "agent" ? page.id : undefined;
|
|
14
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
15
|
+
const known = ctx.db.collection("agent").query("known", {}).value;
|
|
16
|
+
const roster = space
|
|
17
|
+
? ctx.db.collection("thread").query("agents", { in: space }).value
|
|
18
|
+
: { here: [], default: [], agents: {} };
|
|
19
|
+
const seats = open
|
|
20
|
+
? ctx.db.collection("member").find({ member: `agent:${open}` }).value
|
|
21
|
+
: [];
|
|
22
|
+
if (!places || !known || !roster || !seats)
|
|
23
|
+
return null;
|
|
24
|
+
const call = ctx.call;
|
|
25
|
+
const here = places.find((p) => p._id === space);
|
|
26
|
+
const mine = managed(places);
|
|
27
|
+
const groups = [];
|
|
28
|
+
const leading = (id, agent) => {
|
|
29
|
+
const { name, icon } = shownAs(id, agent);
|
|
30
|
+
return _jsx(Avatar, { name: name, kind: "agent", icon: icon, size: 26 });
|
|
31
|
+
};
|
|
32
|
+
// A new agent in a space: a dialog with its form.
|
|
33
|
+
const make = (place, palette, from) => palette.dialog({
|
|
34
|
+
title: say("newAgentIn", { place: placeName(place) }),
|
|
35
|
+
...(from
|
|
36
|
+
? { description: say("startingFrom", { name: shownAs(from, known[from]).name }) }
|
|
37
|
+
: {}),
|
|
38
|
+
view: "agent.add",
|
|
39
|
+
item: { _id: place._id },
|
|
40
|
+
hints: { in: place._id, mode: "new", ...(from ? { from } : {}) },
|
|
41
|
+
});
|
|
42
|
+
if (open && known[open]) {
|
|
43
|
+
const agent = known[open];
|
|
44
|
+
const { name } = shownAs(open, agent);
|
|
45
|
+
const home = agent.in ? places.find((p) => p._id === agent.in) : undefined;
|
|
46
|
+
const working = seats.filter((s) => !s.on);
|
|
47
|
+
const seatHere = here && working.find((s) => s.space === here._id);
|
|
48
|
+
const elsewhere = mine.filter((p) => !working.some((s) => s.space === p._id));
|
|
49
|
+
const items = [];
|
|
50
|
+
if (here && seatHere?.role === "editor" && manages(here) && here.agent !== open) {
|
|
51
|
+
items.push({
|
|
52
|
+
key: "agent:answers",
|
|
53
|
+
label: say("makeNamedAnswerIn", { name, place: placeName(here) }),
|
|
54
|
+
icon: "chat",
|
|
55
|
+
keywords: [say("keywordDefault"), say("keywordAnswer"), say("keywordNewChats")],
|
|
56
|
+
run: () => call("space.agent", { space: here._id, agent: open }),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (elsewhere.length) {
|
|
60
|
+
items.push({
|
|
61
|
+
key: "agent:add-to",
|
|
62
|
+
label: say("addNamedTo", { name }),
|
|
63
|
+
icon: "plus",
|
|
64
|
+
keywords: [say("keywordMember"), say("keywordJoin"), say("keywordWork")],
|
|
65
|
+
step: spaceStep({
|
|
66
|
+
title: say("addToTitle", { name }),
|
|
67
|
+
note: say("addNamedNote"),
|
|
68
|
+
places: elsewhere,
|
|
69
|
+
pick: (place) => call("member.set", {
|
|
70
|
+
space: place._id,
|
|
71
|
+
member: { kind: "agent", id: open },
|
|
72
|
+
role: "editor",
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (home && manages(home)) {
|
|
78
|
+
items.push({
|
|
79
|
+
key: "agent:edit",
|
|
80
|
+
label: say("editNamed", { name }),
|
|
81
|
+
icon: "pencil",
|
|
82
|
+
keywords: [say("keywordChange"), say("keywordInstructions"), say("keywordRename")],
|
|
83
|
+
href: agentPath(open, true),
|
|
84
|
+
});
|
|
85
|
+
items.push({
|
|
86
|
+
key: "agent:delete",
|
|
87
|
+
label: say("deleteMenu", { name }),
|
|
88
|
+
icon: "trash",
|
|
89
|
+
tone: "destructive",
|
|
90
|
+
step: deleteStep({
|
|
91
|
+
agent: open,
|
|
92
|
+
name,
|
|
93
|
+
call,
|
|
94
|
+
after: () => go(placePath(home._id, "members")),
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (!agent.in && mine.length) {
|
|
99
|
+
items.push({
|
|
100
|
+
key: "agent:from",
|
|
101
|
+
label: say("startNewFrom", { name }),
|
|
102
|
+
icon: "sparkles",
|
|
103
|
+
keywords: [say("keywordCopy"), say("keywordLike"), say("keywordCreate")],
|
|
104
|
+
step: spaceStep({
|
|
105
|
+
title: say("newLikeTitle", { name }),
|
|
106
|
+
places: mine,
|
|
107
|
+
pick: (place, palette) => make(place, palette, open),
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (items.length)
|
|
112
|
+
groups.push({ title: say("paletteThisAgent"), order: 10, items });
|
|
113
|
+
}
|
|
114
|
+
if (here && manages(here) && !here.archived && !open) {
|
|
115
|
+
const name = placeName(here);
|
|
116
|
+
const items = [{
|
|
117
|
+
key: "agent:add",
|
|
118
|
+
label: say("addAnAgentTo", { place: name }),
|
|
119
|
+
icon: "bot",
|
|
120
|
+
keywords: [say("keywordMember"), say("keywordInvite"), say("keywordAgent")],
|
|
121
|
+
run: (palette) => palette.dialog({
|
|
122
|
+
title: say("addAnAgentTitle", { place: name }),
|
|
123
|
+
description: say("addAnAgentNote"),
|
|
124
|
+
view: "agent.add",
|
|
125
|
+
item: { _id: here._id },
|
|
126
|
+
hints: { in: here._id },
|
|
127
|
+
}),
|
|
128
|
+
}];
|
|
129
|
+
if (searching) {
|
|
130
|
+
for (const id of roster.here) {
|
|
131
|
+
if (roster.default.includes(id))
|
|
132
|
+
continue;
|
|
133
|
+
const { name: agent } = shownAs(id, roster.agents[id]);
|
|
134
|
+
items.push({
|
|
135
|
+
key: `agent:answers:${id}`,
|
|
136
|
+
label: say("makeNamedAnswer", { name: agent }),
|
|
137
|
+
leading: leading(id, roster.agents[id]),
|
|
138
|
+
description: name,
|
|
139
|
+
keywords: [say("keywordDefault"), say("keywordAnswer"), id],
|
|
140
|
+
run: () => call("space.agent", { space: here._id, agent: id }),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
groups.push({ title: say("paletteThisSpace"), order: 10, items });
|
|
145
|
+
}
|
|
146
|
+
// Agents to go to: those here first (who answers new chats first), then, searching, all met.
|
|
147
|
+
const ids = [
|
|
148
|
+
...roster.here,
|
|
149
|
+
...(searching ? Object.keys(known).filter((id) => !roster.here.includes(id)) : []),
|
|
150
|
+
].filter((id) => id !== open);
|
|
151
|
+
groups.push({
|
|
152
|
+
title: say("paletteAgents"),
|
|
153
|
+
order: 25,
|
|
154
|
+
limit: searching ? SHOWN.searching : SHOWN.idle,
|
|
155
|
+
items: ids.map((id) => {
|
|
156
|
+
const agent = roster.agents[id] ?? known[id];
|
|
157
|
+
const { name } = shownAs(id, agent);
|
|
158
|
+
return {
|
|
159
|
+
key: `agent:${id}`,
|
|
160
|
+
label: name,
|
|
161
|
+
leading: leading(id, agent),
|
|
162
|
+
description: roster.default.includes(id)
|
|
163
|
+
? say("answersNewChatsHere")
|
|
164
|
+
: roster.here.includes(id)
|
|
165
|
+
? say("worksHere", { id })
|
|
166
|
+
: `@${id}`,
|
|
167
|
+
keywords: [id, agent?.description ?? "", say("keywordAgent")].filter(Boolean),
|
|
168
|
+
href: agentPath(id),
|
|
169
|
+
};
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
if (mine.length) {
|
|
173
|
+
const inHere = here && manages(here) && !here.archived ? here : undefined;
|
|
174
|
+
groups.push({
|
|
175
|
+
title: say("paletteCreate"),
|
|
176
|
+
order: 40,
|
|
177
|
+
items: [
|
|
178
|
+
inHere
|
|
179
|
+
? {
|
|
180
|
+
key: "agent:new",
|
|
181
|
+
label: say("newAgent"),
|
|
182
|
+
icon: "bot",
|
|
183
|
+
description: say("newAgentInHere", { place: placeName(inHere) }),
|
|
184
|
+
keywords: [say("keywordCreate"), say("keywordMake"), say("keywordAgent")],
|
|
185
|
+
run: (palette) => make(inHere, palette),
|
|
186
|
+
}
|
|
187
|
+
: {
|
|
188
|
+
key: "agent:new",
|
|
189
|
+
label: say("newAgentInStep"),
|
|
190
|
+
icon: "bot",
|
|
191
|
+
keywords: [say("keywordCreate"), say("keywordMake"), say("keywordAgent")],
|
|
192
|
+
step: spaceStep({
|
|
193
|
+
title: say("newAgentInStep"),
|
|
194
|
+
note: say("newAgentInNote"),
|
|
195
|
+
places: mine,
|
|
196
|
+
pick: (place, palette) => make(place, palette),
|
|
197
|
+
}),
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return groups;
|
|
203
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents' steps in the command palette: picking one of the spaces the
|
|
3
|
+
* person manages (to add an agent there, or make one there), and deleting
|
|
4
|
+
* an agent, a question that says what it means before it's done.
|
|
5
|
+
*/
|
|
6
|
+
import { type PaletteControl, type PaletteStep } from "pairz/web";
|
|
7
|
+
import { type Place } from "./places.js";
|
|
8
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
9
|
+
/** A space they manage, picked: what happens there is `pick`'s. */
|
|
10
|
+
export declare function spaceStep({ title, note, places, pick }: {
|
|
11
|
+
title: string;
|
|
12
|
+
note?: string;
|
|
13
|
+
places: Place[];
|
|
14
|
+
pick(place: Place, palette: PaletteControl): unknown;
|
|
15
|
+
}): PaletteStep;
|
|
16
|
+
/** Deleting an agent, once they've read what it means; then `after`. */
|
|
17
|
+
export declare function deleteStep({ agent, name, call, after }: {
|
|
18
|
+
agent: string;
|
|
19
|
+
name: string;
|
|
20
|
+
call: Call;
|
|
21
|
+
after(): void;
|
|
22
|
+
}): PaletteStep;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Agents' steps in the command palette: picking one of the spaces the
|
|
4
|
+
* person manages (to add an agent there, or make one there), and deleting
|
|
5
|
+
* an agent, a question that says what it means before it's done.
|
|
6
|
+
*/
|
|
7
|
+
import { Avatar } from "pairz/web";
|
|
8
|
+
import { placeName } from "./places.js";
|
|
9
|
+
import { say } from "./words.js";
|
|
10
|
+
/** A space they manage, picked: what happens there is `pick`'s. */
|
|
11
|
+
export function spaceStep({ title, note, places, pick }) {
|
|
12
|
+
return {
|
|
13
|
+
title,
|
|
14
|
+
placeholder: say("findSpace"),
|
|
15
|
+
...(note ? { note } : {}),
|
|
16
|
+
items: () => [{
|
|
17
|
+
title: say("spacesYouManage"),
|
|
18
|
+
items: places.map((place) => ({
|
|
19
|
+
key: `agent-space:${place._id}`,
|
|
20
|
+
label: placeName(place),
|
|
21
|
+
...(place.kind === "personal"
|
|
22
|
+
? {
|
|
23
|
+
icon: "person",
|
|
24
|
+
description: say("justYou"),
|
|
25
|
+
keywords: [say("keywordPersonal")],
|
|
26
|
+
}
|
|
27
|
+
: { leading: _jsx(Avatar, { name: place.name, kind: "space", size: 26 }) }),
|
|
28
|
+
run: (palette) => pick(place, palette),
|
|
29
|
+
})),
|
|
30
|
+
}],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Deleting an agent, once they've read what it means; then `after`. */
|
|
34
|
+
export function deleteStep({ agent, name, call, after }) {
|
|
35
|
+
return {
|
|
36
|
+
title: say("deleteTitle", { name }),
|
|
37
|
+
confirm: true,
|
|
38
|
+
note: say("deleteStepNote"),
|
|
39
|
+
items: () => [{
|
|
40
|
+
title: "",
|
|
41
|
+
items: [
|
|
42
|
+
{
|
|
43
|
+
key: "agent:delete",
|
|
44
|
+
label: say("deleteButton", { name }),
|
|
45
|
+
icon: "trash",
|
|
46
|
+
tone: "destructive",
|
|
47
|
+
run: async () => {
|
|
48
|
+
await call("agent.delete", { agent });
|
|
49
|
+
after();
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{ key: "agent:keep", label: say("deleteStepKeep"), icon: "close", run: (p) => p.back() },
|
|
53
|
+
],
|
|
54
|
+
}],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An agent's page (kind `agent`, at `/agent/<id>`): who it is (its emoji,
|
|
3
|
+
* its name and what it's called by, what it does, where it belongs), where
|
|
4
|
+
* it works among the person's spaces (its role there, and where it answers
|
|
5
|
+
* new chats), and what it's told: its instructions, model and tools. "Ask"
|
|
6
|
+
* starts a chat where it works, `@name` ready. Those who manage where it
|
|
7
|
+
* belongs change it in place (`?edit=1` opens it so) and delete it, after
|
|
8
|
+
* a question that says it leaves every space it works in. The org's team
|
|
9
|
+
* (the app's agents, and those the org made, `in: "*"`) is its owners' and
|
|
10
|
+
* admins': they change one in place (one of the app's becomes the org's
|
|
11
|
+
* version of it, its model still the tier's) and take it off the team;
|
|
12
|
+
* anyone else reads it, and a space's manager starts a new agent from one.
|
|
13
|
+
* Its menu adds it to another space they manage, and has it answer new chats
|
|
14
|
+
* where the person is.
|
|
15
|
+
*/
|
|
16
|
+
import { type ReactNode } from "react";
|
|
17
|
+
import type { ViewContext } from "pairz";
|
|
18
|
+
export declare const agentView: (item: {
|
|
19
|
+
_id?: string;
|
|
20
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* An agent's page (kind `agent`, at `/agent/<id>`): who it is (its emoji,
|
|
4
|
+
* its name and what it's called by, what it does, where it belongs), where
|
|
5
|
+
* it works among the person's spaces (its role there, and where it answers
|
|
6
|
+
* new chats), and what it's told: its instructions, model and tools. "Ask"
|
|
7
|
+
* starts a chat where it works, `@name` ready. Those who manage where it
|
|
8
|
+
* belongs change it in place (`?edit=1` opens it so) and delete it, after
|
|
9
|
+
* a question that says it leaves every space it works in. The org's team
|
|
10
|
+
* (the app's agents, and those the org made, `in: "*"`) is its owners' and
|
|
11
|
+
* admins': they change one in place (one of the app's becomes the org's
|
|
12
|
+
* version of it, its model still the tier's) and take it off the team;
|
|
13
|
+
* anyone else reads it, and a space's manager starts a new agent from one.
|
|
14
|
+
* Its menu adds it to another space they manage, and has it answer new chats
|
|
15
|
+
* where the person is.
|
|
16
|
+
*/
|
|
17
|
+
import { useEffect, useState } from "react";
|
|
18
|
+
import { Avatar, Badge, Button, Card, DetailList, Dialog, EmptyState, go, Icon, IconButton, LongText, Menu, message, Notice, openPalette, Page, Skeleton, Title, } from "pairz/web";
|
|
19
|
+
import { runs, useStanding } from "pairz/plugins/interfaces/contract";
|
|
20
|
+
import { AgentFields } from "./agent-fields.js";
|
|
21
|
+
import { KindField } from "./agent-describe.js";
|
|
22
|
+
import { spaceStep } from "./agent-steps.js";
|
|
23
|
+
import { agentPath, listed, shownAs } from "./agents.js";
|
|
24
|
+
import { managed, manages, placeName, placePath } from "./places.js";
|
|
25
|
+
import { STYLE } from "./style.js";
|
|
26
|
+
import { sayText } from "pairz/web/words";
|
|
27
|
+
import { say } from "./words.js";
|
|
28
|
+
/** Where the org's own agents belong, as the access plugin keeps it: the org itself. */
|
|
29
|
+
const ORG = "*";
|
|
30
|
+
export const agentView = (item, ctx) => {
|
|
31
|
+
const id = item._id ?? "";
|
|
32
|
+
const here = typeof ctx.hints.in === "string" ? ctx.hints.in : undefined;
|
|
33
|
+
const roster = ctx.db.collection("thread").query("agents", {
|
|
34
|
+
...(here ? { in: here } : {}),
|
|
35
|
+
names: [id],
|
|
36
|
+
}).value;
|
|
37
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
38
|
+
const options = ctx.db.collection("agent").query("options", {}).value;
|
|
39
|
+
const seats = ctx.db.collection("member").find({ member: `agent:${id}` }).value;
|
|
40
|
+
// Kinds of work, where tiers give agents their models (their front end says so: `agentKinds`).
|
|
41
|
+
const kindsAsked = !!ctx.resources.agentKinds?.query;
|
|
42
|
+
const tiers = kindsAsked
|
|
43
|
+
? ctx.db.collection("modelChoice").query("offered", {}).value
|
|
44
|
+
: undefined;
|
|
45
|
+
const style = _jsx("style", { href: "team-web", precedence: "pairz", children: STYLE });
|
|
46
|
+
if (!roster || !places || !options || !seats || (kindsAsked && !tiers)) {
|
|
47
|
+
return (_jsxs(Page, { title: _jsx(Skeleton, { width: 200, height: 30 }), leading: _jsx(Skeleton, { width: 52, height: 52 }), children: [style, _jsxs("div", { className: "agent-page", "aria-busy": "true", children: [_jsx(Skeleton, { height: 64, radius: "xl" }), _jsx(Skeleton, { height: 160, radius: "xl" })] })] }));
|
|
48
|
+
}
|
|
49
|
+
const agent = roster.agents[id];
|
|
50
|
+
if (!agent) {
|
|
51
|
+
return (_jsxs("div", { className: "agent-missing", children: [style, _jsx(Title, { text: say("noSuchAgentTitle") }), _jsx(EmptyState, { icon: "bot", heading: "h1", title: say("noSuchAgent"), action: _jsx(Button, { variant: "primary", icon: "compose", href: "/", children: say("goHome") }), children: say("noSuchAgentBody") })] }));
|
|
52
|
+
}
|
|
53
|
+
const query = (ctx.hints.query ?? {});
|
|
54
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(AgentPage, { id: id, agent: agent, here: places.find((p) => p._id === here), answers: !!here && roster.here.includes(id) && roster.default.includes(id), places: places, seats: seats.filter((s) => !s.on), options: options, kinds: tiers?.kinds.map((k) => ({
|
|
55
|
+
kind: k.kind,
|
|
56
|
+
title: sayText(k.title),
|
|
57
|
+
agents: k.agents.map((a) => a.name),
|
|
58
|
+
})), editing: query.edit === "1", call: ctx.call }, id)] }));
|
|
59
|
+
};
|
|
60
|
+
function AgentPage({ id, agent, here, answers, places, seats, options, kinds, editing: asked, call }) {
|
|
61
|
+
const { name, icon } = shownAs(id, agent);
|
|
62
|
+
const home = agent.in ? places.find((p) => p._id === agent.in) : undefined;
|
|
63
|
+
const app = !agent.in;
|
|
64
|
+
// The org's team: the app's agents (as they are, or the org's version) and the org's own.
|
|
65
|
+
const team = app || agent.in === ORG;
|
|
66
|
+
// One of the app's, as it is or as the org changed it: its model is the tier's.
|
|
67
|
+
const appBased = app || (agent.in === ORG && agent.default === true);
|
|
68
|
+
const standing = useStanding(call, team);
|
|
69
|
+
const runsTeam = !!standing && runs(standing);
|
|
70
|
+
const edits = team ? runsTeam : !!home && manages(home);
|
|
71
|
+
const [editing, setEditing] = useState(asked && edits);
|
|
72
|
+
// Asked for in the address (`?edit=1`) before the person's standing was known: open it once it is.
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (asked && edits)
|
|
75
|
+
setEditing(true);
|
|
76
|
+
}, [asked, edits]);
|
|
77
|
+
const [deleting, setDeleting] = useState(false);
|
|
78
|
+
const [error, setError] = useState();
|
|
79
|
+
const placeOf = (space) => places.find((p) => p._id === space);
|
|
80
|
+
const working = seats.flatMap((s) => {
|
|
81
|
+
const place = placeOf(s.space);
|
|
82
|
+
return place ? [{ seat: s, place }] : [];
|
|
83
|
+
});
|
|
84
|
+
const mine = managed(places);
|
|
85
|
+
const elsewhere = mine.filter((p) => !seats.some((s) => s.space === p._id));
|
|
86
|
+
const seatHere = here && seats.find((s) => s.space === here._id);
|
|
87
|
+
// Back to the space the person is in, if it works there; else to where it belongs.
|
|
88
|
+
const back = seatHere ? here : home;
|
|
89
|
+
const backTo = back
|
|
90
|
+
? { href: placePath(back._id, "members"), label: placeName(back) }
|
|
91
|
+
: team
|
|
92
|
+
? { href: "/org?tab=models", label: say("orgsTeam") }
|
|
93
|
+
: undefined;
|
|
94
|
+
// Where asking it starts a chat: here if it answers chats here, else where it does.
|
|
95
|
+
const ask = seatHere?.role === "editor"
|
|
96
|
+
? here
|
|
97
|
+
: working.find((w) => w.seat.role === "editor" && !w.place.archived)?.place;
|
|
98
|
+
const askAt = (place) => `/?in=${encodeURIComponent(place._id)}&to=${encodeURIComponent(id)}`;
|
|
99
|
+
const done = () => {
|
|
100
|
+
setEditing(false);
|
|
101
|
+
if (asked)
|
|
102
|
+
go(agentPath(id));
|
|
103
|
+
};
|
|
104
|
+
const addStep = () => openPalette(spaceStep({
|
|
105
|
+
title: say("addToTitle", { name }),
|
|
106
|
+
note: say("addToNote"),
|
|
107
|
+
places: elsewhere,
|
|
108
|
+
pick: (place) => call("member.set", {
|
|
109
|
+
space: place._id,
|
|
110
|
+
member: { kind: "agent", id },
|
|
111
|
+
role: "editor",
|
|
112
|
+
}),
|
|
113
|
+
}));
|
|
114
|
+
const fromStep = () => openPalette(spaceStep({
|
|
115
|
+
title: say("newLikeTitle", { name }),
|
|
116
|
+
note: say("newLikeNote"),
|
|
117
|
+
places: mine,
|
|
118
|
+
pick: (place, palette) => palette.dialog({
|
|
119
|
+
title: say("newAgentIn", { place: placeName(place) }),
|
|
120
|
+
description: say("startingFrom", { name }),
|
|
121
|
+
view: "agent.add",
|
|
122
|
+
item: { _id: place._id },
|
|
123
|
+
hints: { in: place._id, mode: "new", from: id },
|
|
124
|
+
}),
|
|
125
|
+
}));
|
|
126
|
+
const more = [
|
|
127
|
+
...(here && seatHere?.role === "editor" && !answers && manages(here)
|
|
128
|
+
? [{
|
|
129
|
+
label: say("makeAnswerIn", { place: placeName(here) }),
|
|
130
|
+
icon: "chat",
|
|
131
|
+
onSelect: () => void call("space.agent", { space: here._id, agent: id }).catch((e) => setError(message(e))),
|
|
132
|
+
}]
|
|
133
|
+
: []),
|
|
134
|
+
...(elsewhere.length
|
|
135
|
+
? [{ label: say("addToSpaceMenu"), icon: "plus", onSelect: addStep }]
|
|
136
|
+
: []),
|
|
137
|
+
...(appBased && mine.length
|
|
138
|
+
? [{ label: say("startFromIt"), icon: "sparkles", onSelect: fromStep }]
|
|
139
|
+
: []),
|
|
140
|
+
...(edits
|
|
141
|
+
? [
|
|
142
|
+
"separator",
|
|
143
|
+
{
|
|
144
|
+
label: team ? say("removeFromTeamMenu") : say("deleteMenu", { name }),
|
|
145
|
+
icon: "trash",
|
|
146
|
+
tone: "destructive",
|
|
147
|
+
onSelect: () => setDeleting(true),
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
: []),
|
|
151
|
+
];
|
|
152
|
+
return (_jsxs(Page, { className: "agent-page-frame", leading: _jsx(Avatar, { name: name, kind: "agent", icon: icon, size: 52, className: "agent-mark" }), title: name, back: backTo, badges: _jsxs(_Fragment, { children: [_jsxs(Badge, { variant: "outline", className: "agent-page-handle", children: ["@", id] }), app ? _jsx(Badge, { children: say("partOfApp") }) : agent.in === ORG
|
|
153
|
+
? (_jsx(Badge, { tone: "primary", children: appBased ? say("changedForOrg") : say("orgsTeam") }))
|
|
154
|
+
: (_jsx(Badge, { tone: "primary", children: home ? say("madeIn", { place: placeName(home) }) : say("madeElsewhere") })), answers && here ? _jsx(Badge, { tone: "success", children: say("answersNewChatsHere") }) : null] }), description: agent.description && sayText(agent.description), actions: editing ? null : (_jsxs(_Fragment, { children: [ask
|
|
155
|
+
? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", icon: "chat", href: askAt(ask), className: "agent-wide", children: say("askAgent", { name }) }), _jsx(IconButton, { icon: "chat", label: say("askAgent", { name }), variant: "primary", href: askAt(ask), className: "agent-narrow" })] }))
|
|
156
|
+
: null, edits
|
|
157
|
+
? (_jsxs(_Fragment, { children: [_jsx(Button, { icon: "pencil", className: "agent-wide", onClick: () => setEditing(true), children: say("edit") }), _jsx(IconButton, { icon: "pencil", label: say("editAgent", { name }), variant: "outline", className: "agent-narrow", onClick: () => setEditing(true) })] }))
|
|
158
|
+
: null, more.length ? _jsx(Menu, { label: say("moreMenu", { name }), align: "end", items: more }) : null] })), children: [_jsx(Title, { text: name }), error
|
|
159
|
+
? _jsx(Notice, { tone: "destructive", role: "alert", className: "agent-page-error", children: error })
|
|
160
|
+
: null, editing
|
|
161
|
+
? (_jsx(Edit, { id: id, agent: agent, options: options, call: call, done: done, tierModel: appBased, kinds: kinds }))
|
|
162
|
+
: (_jsxs("div", { className: "agent-page", children: [app && !runsTeam
|
|
163
|
+
? (_jsx(Notice, { tone: "neutral", icon: "lock", action: mine.length
|
|
164
|
+
? (_jsx(Button, { size: "sm", icon: "sparkles", onClick: fromStep, children: say("startFromShort") }))
|
|
165
|
+
: null, children: say("appAgentNotice") }))
|
|
166
|
+
: !edits
|
|
167
|
+
? (_jsxs("p", { className: "agent-page-note", children: [_jsx(Icon, { name: "lock", size: 14 }), home
|
|
168
|
+
? say("managersChangeIt", { place: placeName(home) })
|
|
169
|
+
: say("managersChangeItElsewhere")] }))
|
|
170
|
+
: null, _jsxs("section", { className: "agent-section", "aria-labelledby": "agent-works", children: [_jsxs("div", { className: "agent-section-head", children: [_jsx("h2", { id: "agent-works", className: "agent-section-title", children: say.nodes("worksIn", {
|
|
171
|
+
count: _jsx("span", { className: "agent-count", children: working.length }),
|
|
172
|
+
}) }), elsewhere.length
|
|
173
|
+
? (_jsx(Button, { size: "sm", variant: "ghost", icon: "plus", onClick: addStep, children: say("addToSpace") }))
|
|
174
|
+
: null] }), working.length
|
|
175
|
+
? (_jsx("ul", { className: "agent-seats", children: working.map(({ seat, place }) => (_jsx("li", { children: _jsxs("a", { className: "agent-seat", href: placePath(place._id, "members"), children: [place.kind === "personal"
|
|
176
|
+
? (_jsx("span", { className: "agent-seat-personal", children: _jsx(Icon, { name: "person", size: 15 }) }))
|
|
177
|
+
: _jsx(Avatar, { name: place.name, kind: "space", size: 28 }), _jsx("span", { className: "agent-seat-name", children: placeName(place) }), place.agent === id
|
|
178
|
+
? _jsx(Badge, { tone: "primary", children: say("answersNewChats") })
|
|
179
|
+
: null, _jsx(Badge, { variant: "outline", children: seat.role === "viewer" ? say("roleViewer") : say("roleEditor") }), _jsx(Icon, { name: "chevron", size: 15 })] }) }, seat._id))) }))
|
|
180
|
+
: _jsx("p", { className: "agent-none", children: say("worksNowhere") })] }), _jsxs("section", { className: "agent-section", "aria-labelledby": "agent-told", children: [_jsx("h2", { id: "agent-told", className: "agent-section-title", children: say("instructions") }), _jsx(Card, { className: "agent-instructions-read", children: _jsx(LongText, { text: agent.instructions, lines: 12 }) })] }), _jsxs("section", { className: "agent-section", "aria-labelledby": "agent-uses", children: [_jsx("h2", { id: "agent-uses", className: "agent-section-title", children: say("modelAndTools") }), _jsx(DetailList, { item: {}, fields: [
|
|
181
|
+
{
|
|
182
|
+
field: "model",
|
|
183
|
+
label: say("model"),
|
|
184
|
+
value: _jsx("code", { children: modelName(agent.model) }),
|
|
185
|
+
},
|
|
186
|
+
...(agent.effort
|
|
187
|
+
? [{
|
|
188
|
+
field: "effort",
|
|
189
|
+
label: say("thinks"),
|
|
190
|
+
value: say("effort", { effort: agent.effort }),
|
|
191
|
+
}]
|
|
192
|
+
: []),
|
|
193
|
+
{
|
|
194
|
+
field: "tools",
|
|
195
|
+
label: say("tools"),
|
|
196
|
+
value: agent.tools?.length
|
|
197
|
+
? _jsx(ToolList, { tools: agent.tools, options: options })
|
|
198
|
+
: say("noTools"),
|
|
199
|
+
},
|
|
200
|
+
] })] })] })), edits
|
|
201
|
+
? (_jsx(Delete, { open: deleting, onClose: () => setDeleting(false), id: id, name: name, spaces: working.map((w) => placeName(w.place)), after: home ? placePath(home._id, "members") : team ? "/org?tab=models" : "/", call: call, ...(team ? { team: appBased ? "back" : "gone" } : {}) }))
|
|
202
|
+
: null] }));
|
|
203
|
+
}
|
|
204
|
+
/** How many tools show before "Show all". */
|
|
205
|
+
const TOOLS = 8;
|
|
206
|
+
/** The tools it uses, each with what it does; past a few, the rest on a press. */
|
|
207
|
+
function ToolList({ tools, options }) {
|
|
208
|
+
const [all, setAll] = useState(false);
|
|
209
|
+
const shown = all ? tools : tools.slice(0, TOOLS);
|
|
210
|
+
return (_jsxs("div", { className: "agent-tools-read", children: [_jsx("ul", { className: "agent-tool-list", children: shown.map((tool) => {
|
|
211
|
+
const about = options.tools.find((t) => t.name === tool)?.description;
|
|
212
|
+
return (_jsxs("li", { title: about, children: [_jsx("code", { children: tool }), _jsx("span", { children: about ?? "" })] }, tool));
|
|
213
|
+
}) }), tools.length > TOOLS
|
|
214
|
+
? (_jsx(Button, { variant: "link", size: "sm", iconEnd: all ? undefined : "chevron-down", onClick: () => setAll(!all), children: all ? say("showFewer") : say("showAll", { count: tools.length }) }))
|
|
215
|
+
: null] }));
|
|
216
|
+
}
|
|
217
|
+
/** A model, as it's named: `"provider/model"`, an alias, or a list tried in order. */
|
|
218
|
+
const modelName = (model) => typeof model === "string"
|
|
219
|
+
? model
|
|
220
|
+
: Array.isArray(model)
|
|
221
|
+
? model.map(modelName).join(say("modelsThenJoin"))
|
|
222
|
+
: modelName(model.model);
|
|
223
|
+
/** Changing it, in place: its fields, then Save (what changed only) or Cancel. */
|
|
224
|
+
function Edit({ id, agent, options, call, done, tierModel, kinds }) {
|
|
225
|
+
const wasLike = agent.like && kinds?.some((k) => k.kind === agent.like)
|
|
226
|
+
? agent.like
|
|
227
|
+
: kinds?.[0]?.kind ?? "";
|
|
228
|
+
const [like, setLike] = useState(wasLike);
|
|
229
|
+
const was = {
|
|
230
|
+
name: shownAs(id, agent).name,
|
|
231
|
+
icon: agent.icon ?? "",
|
|
232
|
+
description: agent.description ?? "",
|
|
233
|
+
instructions: agent.instructions,
|
|
234
|
+
model: typeof agent.model === "string" ? agent.model : options.models[0] ?? "",
|
|
235
|
+
tools: agent.tools ?? [],
|
|
236
|
+
};
|
|
237
|
+
const [draft, setDraft] = useState(was);
|
|
238
|
+
const [busy, setBusy] = useState(false);
|
|
239
|
+
const [error, setError] = useState();
|
|
240
|
+
const changed = {
|
|
241
|
+
...changes(was, draft),
|
|
242
|
+
...(kinds?.length && !tierModel && like !== wasLike ? { like } : {}),
|
|
243
|
+
};
|
|
244
|
+
// Where tiers give it its model, nothing's chosen here: the model isn't sent.
|
|
245
|
+
if (kinds?.length || tierModel)
|
|
246
|
+
delete changed.model;
|
|
247
|
+
const ready = !!draft.name.trim() && (!!kinds?.length || !!tierModel || !!draft.model);
|
|
248
|
+
return (_jsxs("form", { className: "agent-edit", "aria-label": say("changeAgent", { name: was.name }), onSubmit: async (event) => {
|
|
249
|
+
event.preventDefault();
|
|
250
|
+
if (!ready || busy)
|
|
251
|
+
return;
|
|
252
|
+
if (!Object.keys(changed).length)
|
|
253
|
+
return done();
|
|
254
|
+
setBusy(true);
|
|
255
|
+
setError(undefined);
|
|
256
|
+
try {
|
|
257
|
+
await call("agent.update", { agent: id, ...changed });
|
|
258
|
+
done();
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
setError(message(e));
|
|
262
|
+
setBusy(false);
|
|
263
|
+
}
|
|
264
|
+
}, children: [_jsx(Card, { className: "agent-edit-card", children: _jsx(AgentFields, { value: draft, onChange: (patch) => setDraft((now) => ({ ...now, ...patch })), options: options, handle: id, call: call, autoFocus: true, disabled: busy, model: tierModel
|
|
265
|
+
? (_jsx(Notice, { tone: "neutral", icon: "sparkles", children: say.nodes("tierModel", {
|
|
266
|
+
place: _jsx("a", { href: "/org?tab=models", children: say("tierModelPlace") }),
|
|
267
|
+
}) }))
|
|
268
|
+
: kinds?.length
|
|
269
|
+
? _jsx(KindField, { kinds: kinds, value: like, onChange: setLike, disabled: busy })
|
|
270
|
+
: undefined }) }), _jsxs("div", { className: "agent-edit-end", children: [_jsx("p", { className: "agent-form-note", "aria-live": "polite", children: error
|
|
271
|
+
? _jsx("span", { className: "agent-error", role: "alert", children: error })
|
|
272
|
+
: say("keepsHandle", { handle: id }) }), _jsx(Button, { onClick: done, disabled: busy, children: say("cancel") }), _jsx(Button, { type: "submit", variant: "primary", icon: "check", loading: busy, disabled: !ready || !Object.keys(changed).length, children: say("saveChanges") })] })] }));
|
|
273
|
+
}
|
|
274
|
+
/** What changed between what an agent was and what's typed, as `agent.update` takes it. */
|
|
275
|
+
function changes(was, now) {
|
|
276
|
+
const out = {};
|
|
277
|
+
for (const field of ["name", "icon", "description", "instructions", "model"]) {
|
|
278
|
+
const value = now[field].trim();
|
|
279
|
+
if (value !== was[field].trim() && (value || field !== "name"))
|
|
280
|
+
out[field] = value;
|
|
281
|
+
}
|
|
282
|
+
if (now.tools.join() !== was.tools.join())
|
|
283
|
+
out.tools = now.tools;
|
|
284
|
+
return out;
|
|
285
|
+
}
|
|
286
|
+
/** Deleting it, once they've read what it means: it leaves every space it works in. */
|
|
287
|
+
function Delete({ open, onClose, id, name, spaces, after, call, team }) {
|
|
288
|
+
const [busy, setBusy] = useState(false);
|
|
289
|
+
const [error, setError] = useState();
|
|
290
|
+
return (_jsxs(Dialog, { open: open, onClose: onClose, size: "sm", title: team ? say("removeTeamTitle", { name }) : say("deleteTitle", { name }), footer: _jsxs(_Fragment, { children: [_jsx(Button, { onClick: onClose, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "destructive", icon: "trash", loading: busy, onClick: async () => {
|
|
291
|
+
setBusy(true);
|
|
292
|
+
setError(undefined);
|
|
293
|
+
try {
|
|
294
|
+
await call("agent.delete", { agent: id });
|
|
295
|
+
onClose();
|
|
296
|
+
go(after);
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
setError(message(e));
|
|
300
|
+
setBusy(false);
|
|
301
|
+
}
|
|
302
|
+
}, children: team ? say("removeButton") : say("deleteButton", { name }) })] }), children: [team
|
|
303
|
+
? (_jsxs("ul", { className: "agent-delete-means", children: [_jsx("li", { children: say.nodes("teamLeaves", { bold: _jsx("b", { children: say("teamLeavesBold") }) }) }), _jsx("li", { children: say("teamSaidStays") }), _jsx("li", { children: team === "back" ? say("teamAddBack") : say("teamDeleted") })] }))
|
|
304
|
+
: (_jsxs("ul", { className: "agent-delete-means", children: [_jsx("li", { children: spaces.length
|
|
305
|
+
? say.nodes("deleteLeavesNamed", {
|
|
306
|
+
bold: _jsx("b", { children: say("deleteLeavesBold") }),
|
|
307
|
+
spaces: listed(spaces),
|
|
308
|
+
})
|
|
309
|
+
: say.nodes("deleteLeaves", { bold: _jsx("b", { children: say("deleteLeavesBold") }) }) }), _jsx("li", { children: say.nodes("deleteGone", { bold: _jsx("b", { children: say("deleteGoneBold") }) }) }), _jsx("li", { children: say.nodes("deleteChats", { bold: _jsx("b", { children: say("deleteChatsBold") }) }) })] })), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null] }));
|
|
310
|
+
}
|