@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,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* What an agent is, as a form: its emoji and name (and what it's called by,
|
|
4
|
+
* `@maya`), what it does, its instructions (written for the person from the
|
|
5
|
+
* two with `agent.draft` if they like: a moment on a real model, said so
|
|
6
|
+
* while it writes, and undone with a press), the model it thinks with, and
|
|
7
|
+
* the tools it may use (those it has, in a line; all of them to tick, on a
|
|
8
|
+
* press). Making an agent (`NewAgent`) and changing one (its page) show it;
|
|
9
|
+
* what's typed goes up as it changes (`onChange`, a patch).
|
|
10
|
+
*/
|
|
11
|
+
import { useId, useState } from "react";
|
|
12
|
+
import { Avatar, Button, Checkbox, Field, Icon, Input, message, Skeleton, Spinner, Textarea, } from "pairz/web";
|
|
13
|
+
import { ICONS } from "./agents.js";
|
|
14
|
+
import { ModelPicker } from "./model-picker.js";
|
|
15
|
+
import { say } from "./words.js";
|
|
16
|
+
/** How many tools the line shows before it counts the rest. */
|
|
17
|
+
const LINE = 6;
|
|
18
|
+
export function AgentFields({ value, onChange, options, handle, call, autoFocus, disabled, model }) {
|
|
19
|
+
const id = useId();
|
|
20
|
+
const own = !!value.icon && !ICONS.includes(value.icon);
|
|
21
|
+
return (_jsxs("div", { className: "agent-form", children: [_jsxs("div", { className: "agent-form-who", children: [value.name.trim() || value.icon
|
|
22
|
+
? _jsx(Avatar, { name: value.name.trim() || "?", kind: "agent", icon: value.icon, size: 56 })
|
|
23
|
+
: (_jsx("span", { className: "agent-face-empty", "aria-hidden": "true", children: _jsx(Icon, { name: "bot", size: 24 }) })), _jsx(Field, { label: say("fieldName"), className: "agent-form-name", hint: handle
|
|
24
|
+
? say.nodes("calledIn", { handle: _jsxs("b", { className: "agent-handle", children: ["@", handle] }) })
|
|
25
|
+
: say("nameHint"), children: (control) => (_jsx(Input, { ...control, value: value.name, maxLength: 60, placeholder: say("namePlaceholder"), autoComplete: "off", autoFocus: autoFocus, disabled: disabled, onChange: (event) => onChange({ name: event.target.value }) })) })] }), _jsxs("div", { className: "agent-form-field", role: "radiogroup", "aria-labelledby": `${id}-icon`, children: [_jsx("span", { id: `${id}-icon`, className: "agent-form-label", children: say("emoji") }), _jsxs("div", { className: "agent-icons", children: [_jsx("button", { type: "button", role: "radio", "aria-checked": !value.icon, "aria-label": say("noEmoji"), title: say("noEmoji"), className: "agent-icon agent-icon-none", disabled: disabled, onClick: () => onChange({ icon: "" }), children: (value.name.trim()[0] ?? "A").toUpperCase() }), ICONS.map((icon) => (_jsx("button", { type: "button", role: "radio", "aria-checked": value.icon === icon, className: "agent-icon", disabled: disabled, onClick: () => onChange({ icon }), children: icon }, icon))), _jsx(Input, { size: "sm", className: "agent-icon-own", "aria-label": say("anotherEmoji"), placeholder: say("otherEmoji"), value: own ? value.icon : "", maxLength: 16, autoComplete: "off", disabled: disabled, "data-chosen": own || undefined, onChange: (event) => onChange({ icon: event.target.value.trim() }) })] })] }), _jsx(Field, { label: say("fieldDoes"), hint: say("doesHint"), children: (control) => (_jsx(Textarea, { ...control, rows: 2, autoGrow: true, maxHeight: 160, maxLength: 500, value: value.description, placeholder: say("doesPlaceholder"), disabled: disabled, onChange: (event) => onChange({ description: event.target.value }) })) }), _jsx(Instructions, { value: value, onChange: onChange, call: call, disabled: disabled }), model !== undefined ? model : (_jsx(Field, { label: say("model"), hint: say("modelHint"), children: (control) => (_jsx(ModelPicker, { id: control.id, value: value.model, call: call, disabled: disabled, onChange: (model) => onChange({ model }) })) })), _jsx(Tools, { value: value.tools, onChange: (tools) => onChange({ tools }), options: options })] }));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Its instructions: typed, or written for the person from its name and
|
|
29
|
+
* what it should do (`agent.draft`), which takes a moment on a real model:
|
|
30
|
+
* the box says so while it writes, and what it replaced comes back with Undo.
|
|
31
|
+
*/
|
|
32
|
+
function Instructions({ value, onChange, call, disabled }) {
|
|
33
|
+
const id = useId();
|
|
34
|
+
const [drafting, setDrafting] = useState(false);
|
|
35
|
+
const [error, setError] = useState();
|
|
36
|
+
const [before, setBefore] = useState();
|
|
37
|
+
const name = value.name.trim();
|
|
38
|
+
const ready = !!name && !!value.description.trim();
|
|
39
|
+
const draft = async () => {
|
|
40
|
+
setDrafting(true);
|
|
41
|
+
setError(undefined);
|
|
42
|
+
try {
|
|
43
|
+
const { instructions } = await call("agent.draft", {
|
|
44
|
+
name,
|
|
45
|
+
description: value.description.trim(),
|
|
46
|
+
...(value.model ? { model: value.model } : {}),
|
|
47
|
+
});
|
|
48
|
+
setBefore(value.instructions);
|
|
49
|
+
onChange({ instructions });
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
setError(message(e));
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
setDrafting(false);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return (_jsxs("div", { className: "agent-form-field", children: [_jsxs("div", { className: "agent-form-label-row", children: [_jsx("label", { className: "agent-form-label", htmlFor: id, children: say("instructions") }), _jsx(Button, { size: "sm", variant: "ghost", icon: "sparkles", className: "agent-draft", loading: drafting, disabled: !ready || disabled, title: ready ? undefined : say("sayNameFirst"), onClick: () => void draft(), children: value.instructions.trim() ? say("rewriteForMe") : say("writeForMe") })] }), _jsxs("div", { className: "agent-instructions", "data-busy": drafting || undefined, children: [_jsx(Textarea, { id: id, rows: 6, autoGrow: true, maxHeight: 420, value: value.instructions, readOnly: drafting, disabled: disabled, "aria-describedby": `${id}-note`, "aria-busy": drafting || undefined, placeholder: say("youArePlaceholder", { name: name || say("youAreDefaultName") }), onChange: (event) => {
|
|
59
|
+
setBefore(undefined);
|
|
60
|
+
onChange({ instructions: event.target.value });
|
|
61
|
+
} }), drafting
|
|
62
|
+
? (_jsxs("div", { className: "agent-drafting", role: "status", children: [_jsxs("span", { className: "agent-drafting-say", children: [_jsx(Spinner, { size: 13 }), say("writingFor", { name })] }), [92, 84, 96, 70, 88, 52].map((width, i) => (_jsx(Skeleton, { height: 11, width: `${width}%` }, i)))] }))
|
|
63
|
+
: null] }), _jsx("p", { id: `${id}-note`, className: "agent-form-note", children: error ? _jsx("span", { className: "agent-error", role: "alert", children: error }) : before !== undefined
|
|
64
|
+
? (_jsxs(_Fragment, { children: [say("draftNote"), " ", _jsx(Button, { variant: "link", size: "sm", className: "agent-undo", onClick: () => {
|
|
65
|
+
onChange({ instructions: before });
|
|
66
|
+
setBefore(undefined);
|
|
67
|
+
}, children: say("undo") })] }))
|
|
68
|
+
: ready || value.instructions.trim()
|
|
69
|
+
? say("instructionsHint")
|
|
70
|
+
: say("instructionsEmptyHint") })] }));
|
|
71
|
+
}
|
|
72
|
+
/** The tools it may use: those it has, in a line; all of them to tick, once opened. */
|
|
73
|
+
function Tools({ value, onChange, options }) {
|
|
74
|
+
const id = useId();
|
|
75
|
+
const [open, setOpen] = useState(false);
|
|
76
|
+
const offered = options.tools.map((t) => t.name);
|
|
77
|
+
const chosen = offered.filter((name) => value.includes(name));
|
|
78
|
+
const toggle = (name, on) => onChange(on ? [...new Set([...value, name])] : value.filter((t) => t !== name));
|
|
79
|
+
return (_jsxs("div", { className: "agent-form-field", role: "group", "aria-labelledby": `${id}-tools`, children: [_jsxs("div", { className: "agent-form-label-row", children: [_jsx("span", { id: `${id}-tools`, className: "agent-form-label", children: say.nodes("toolsLabel", {
|
|
80
|
+
count: (_jsx("span", { className: "agent-form-count", children: say("toolsOf", { chosen: chosen.length, offered: offered.length }) })),
|
|
81
|
+
}) }), _jsx(Button, { size: "sm", variant: "ghost", iconEnd: open ? undefined : "chevron-down", "aria-expanded": open, "aria-controls": `${id}-list`, onClick: () => setOpen(!open), children: open ? say("toolsChooseDone") : say("toolsChoose") })] }), open
|
|
82
|
+
? (_jsxs("div", { id: `${id}-list`, className: "agent-tools", children: [_jsxs("div", { className: "agent-tools-all", children: [_jsx(Button, { size: "sm", variant: "link", onClick: () => onChange(offered), children: say("toolsAll") }), _jsx(Button, { size: "sm", variant: "link", onClick: () => onChange([]), children: say("toolsNone") })] }), _jsx("ul", { children: options.tools.map((t) => (_jsx("li", { children: _jsx(Checkbox, { checked: value.includes(t.name), onChange: (event) => toggle(t.name, event.target.checked), label: _jsxs("span", { className: "agent-tool", children: [_jsx("code", { children: t.name }), _jsx("span", { children: t.description })] }) }) }, t.name))) })] }))
|
|
83
|
+
: (_jsx("p", { id: `${id}-list`, className: "agent-tools-line", children: chosen.length
|
|
84
|
+
? (_jsxs(_Fragment, { children: [chosen.slice(0, LINE).map((name) => _jsx("code", { children: name }, name)), chosen.length > LINE
|
|
85
|
+
? _jsx("span", { children: say("toolsMore", { count: chosen.length - LINE }) })
|
|
86
|
+
: null] }))
|
|
87
|
+
: _jsx("span", { children: say("noTools") }) }))] }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents someone has met, to add to a space: those that don't work there
|
|
3
|
+
* yet (the app's, and those people made where the person reaches), each by
|
|
4
|
+
* its emoji and names, what it does or where it belongs; found as they're
|
|
5
|
+
* typed; each added at once, in the role chosen for them (`member.set`),
|
|
6
|
+
* which says so. First in the list, making a new one instead.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from "react";
|
|
9
|
+
import type { Agent } from "pairz/plugins/agents/contract";
|
|
10
|
+
import { type Place } from "./places.js";
|
|
11
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
12
|
+
/** Where an agent comes from, in a few words. */
|
|
13
|
+
export declare const belongs: (agent: Agent, places: Place[]) => string;
|
|
14
|
+
export declare function KnownAgents({ space, agents, places, call, onNew }: {
|
|
15
|
+
space: Place;
|
|
16
|
+
/** The agents they've met that don't work here, by id. */
|
|
17
|
+
agents: [string, Agent][];
|
|
18
|
+
places: Place[];
|
|
19
|
+
call: Call;
|
|
20
|
+
onNew(): void;
|
|
21
|
+
}): ReactNode;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Agents someone has met, to add to a space: those that don't work there
|
|
4
|
+
* yet (the app's, and those people made where the person reaches), each by
|
|
5
|
+
* its emoji and names, what it does or where it belongs; found as they're
|
|
6
|
+
* typed; each added at once, in the role chosen for them (`member.set`),
|
|
7
|
+
* which says so. First in the list, making a new one instead.
|
|
8
|
+
*/
|
|
9
|
+
import { useId, useState } from "react";
|
|
10
|
+
import { Avatar, Button, Icon, Input, message, Select } from "pairz/web";
|
|
11
|
+
import { AGENT_ROLES } from "pairz/plugins/access/contract";
|
|
12
|
+
import { found, listed, shownAs } from "./agents.js";
|
|
13
|
+
import { placeName } from "./places.js";
|
|
14
|
+
import { sayText } from "pairz/web/words";
|
|
15
|
+
import { say } from "./words.js";
|
|
16
|
+
/** Past this many, there's a field to find one. */
|
|
17
|
+
const FIND = 5;
|
|
18
|
+
/** Where an agent comes from, in a few words. */
|
|
19
|
+
export const belongs = (agent, places) => {
|
|
20
|
+
if (!agent.in)
|
|
21
|
+
return say("oneOfApps");
|
|
22
|
+
const home = places.find((p) => p._id === agent.in);
|
|
23
|
+
return home ? say("madeIn", { place: placeName(home) }) : say("madeInOther");
|
|
24
|
+
};
|
|
25
|
+
export function KnownAgents({ space, agents, places, call, onNew }) {
|
|
26
|
+
const id = useId();
|
|
27
|
+
const [search, setSearch] = useState("");
|
|
28
|
+
const [role, setRole] = useState("editor");
|
|
29
|
+
const [busy, setBusy] = useState();
|
|
30
|
+
const [error, setError] = useState();
|
|
31
|
+
const [added, setAdded] = useState([]);
|
|
32
|
+
const all = agents.map(([key, agent]) => ({ id: key, ...shownAs(key, agent), agent }));
|
|
33
|
+
const shown = found(all, search);
|
|
34
|
+
const where = placeName(space);
|
|
35
|
+
const add = async (agent, name) => {
|
|
36
|
+
setBusy(agent);
|
|
37
|
+
setError(undefined);
|
|
38
|
+
try {
|
|
39
|
+
await call("member.set", { space: space._id, member: { kind: "agent", id: agent }, role });
|
|
40
|
+
setAdded((now) => [...now, name]);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
setError(message(e));
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
setBusy(undefined);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return (_jsxs("div", { className: "agent-known", children: [_jsxs("div", { className: "agent-known-tools", children: [agents.length > FIND
|
|
50
|
+
? (_jsxs(_Fragment, { children: [_jsx("label", { className: "pairz-sr", htmlFor: `${id}-find`, children: say("findAgent") }), _jsx(Input, { id: `${id}-find`, type: "search", icon: "search", size: "sm", className: "agent-known-find", placeholder: say("findAgentKnown"), autoComplete: "off", autoFocus: true, value: search, onChange: (event) => setSearch(event.target.value) })] }))
|
|
51
|
+
: _jsx("p", { className: "agent-known-intro", children: say("knownIntro") }), _jsxs("label", { className: "agent-known-role", children: [_jsx("span", { children: say("addsAs") }), _jsx(Select, { size: "sm", value: role, onChange: (event) => setRole(event.target.value), children: AGENT_ROLES.map((r) => _jsx("option", { value: r.value, children: r.label }, r.value)) })] })] }), _jsxs("ul", { className: "agent-known-list", children: [_jsx("li", { children: _jsxs("button", { type: "button", className: "agent-known-row agent-known-new", onClick: onNew, children: [_jsx("span", { className: "agent-known-plus", children: _jsx(Icon, { name: "plus", size: 18 }) }), _jsxs("span", { className: "agent-known-text", children: [_jsx("span", { className: "agent-known-name", children: say("createNewAgent") }), _jsx("span", { className: "agent-known-what", children: say("createNewAgentBody") })] }), _jsx(Icon, { name: "chevron", size: 16 })] }) }), shown.map((a) => (_jsxs("li", { className: "agent-known-row", children: [_jsx(Avatar, { name: a.name, kind: "agent", icon: a.icon, size: 34 }), _jsxs("span", { className: "agent-known-text", children: [_jsxs("span", { className: "agent-known-name", children: [a.name, " ", _jsxs("span", { className: "agent-handle", children: ["@", a.id] }), _jsx("span", { className: "agent-known-from", children: belongs(a.agent, places) })] }), a.agent.description
|
|
52
|
+
? _jsx("span", { className: "agent-known-what", children: sayText(a.agent.description) })
|
|
53
|
+
: null] }), _jsx(Button, { size: "sm", icon: "plus", loading: busy === a.id, disabled: !!busy && busy !== a.id, "aria-label": say("addAgentTo", { name: a.name, place: where }), onClick: () => void add(a.id, a.name), children: say("add") })] }, a.id)))] }), !shown.length
|
|
54
|
+
? (_jsx("p", { className: "agent-known-none", children: agents.length
|
|
55
|
+
? say("noneCalled", { search: search.trim() })
|
|
56
|
+
: say("allWorkHere", { place: where }) }))
|
|
57
|
+
: null, _jsx("p", { className: "agent-form-note", "aria-live": "polite", children: error
|
|
58
|
+
? _jsx("span", { className: "agent-error", role: "alert", children: error })
|
|
59
|
+
: added.length
|
|
60
|
+
? (_jsxs("span", { className: "agent-done", children: [_jsx(Icon, { name: "check", size: 14 }), say("worksNowNames", { names: listed(added), place: where, count: added.length })] }))
|
|
61
|
+
: AGENT_ROLES.find((r) => r.value === role)?.lets })] }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Making an agent in a space, for those who manage it: one calm form (its
|
|
3
|
+
* fields: `AgentFields`), what it may start from (one of the app's agents,
|
|
4
|
+
* `from`: its words, model and tools filled in), and the role it works in
|
|
5
|
+
* there. Made (`agent.create` there, then `member.set`), it says so, with
|
|
6
|
+
* what's next: have it answer new chats, open its page, or make another.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from "react";
|
|
9
|
+
import type { Agent } from "pairz/plugins/agents/contract";
|
|
10
|
+
import { type KindOption } from "./agent-describe.js";
|
|
11
|
+
import { type Options } from "./agents.js";
|
|
12
|
+
import { type Place } from "./places.js";
|
|
13
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
14
|
+
export declare function NewAgent({ space, known, options, call, from: first, onBack, kinds }: {
|
|
15
|
+
space: Place;
|
|
16
|
+
/** Kinds of work, where tiers give agents their models: one in place of a model. */
|
|
17
|
+
kinds?: KindOption[];
|
|
18
|
+
/** Every agent the person has met: the app's, to start from; and names taken. */
|
|
19
|
+
known: Record<string, Agent>;
|
|
20
|
+
options: Options;
|
|
21
|
+
call: Call;
|
|
22
|
+
/** One of the app's agents to start from. */
|
|
23
|
+
from?: string;
|
|
24
|
+
/** Back to the agents they know, when there are some to add. */
|
|
25
|
+
onBack?(): void;
|
|
26
|
+
}): ReactNode;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Making an agent in a space, for those who manage it: one calm form (its
|
|
4
|
+
* fields: `AgentFields`), what it may start from (one of the app's agents,
|
|
5
|
+
* `from`: its words, model and tools filled in), and the role it works in
|
|
6
|
+
* there. Made (`agent.create` there, then `member.set`), it says so, with
|
|
7
|
+
* what's next: have it answer new chats, open its page, or make another.
|
|
8
|
+
*/
|
|
9
|
+
import { useId, useState } from "react";
|
|
10
|
+
import { Avatar, Button, Field, Icon, message, Select } from "pairz/web";
|
|
11
|
+
import { AGENT_ROLES } from "pairz/plugins/access/contract";
|
|
12
|
+
import { AgentFields } from "./agent-fields.js";
|
|
13
|
+
import { Describe, KindField } from "./agent-describe.js";
|
|
14
|
+
import { agentPath, handleOf, shownAs, usualTools } from "./agents.js";
|
|
15
|
+
import { placeName } from "./places.js";
|
|
16
|
+
import { say } from "./words.js";
|
|
17
|
+
/** A link in a dialog closes it as it's followed: the page it opens is behind. */
|
|
18
|
+
const leaving = (event) => event.currentTarget.closest("dialog")?.close();
|
|
19
|
+
export function NewAgent({ space, known, options, call, from: first, onBack, kinds }) {
|
|
20
|
+
const id = useId();
|
|
21
|
+
const offered = options.tools.map((t) => t.name);
|
|
22
|
+
const app = Object.entries(known).filter(([, agent]) => !agent.in);
|
|
23
|
+
const blank = () => ({
|
|
24
|
+
name: "",
|
|
25
|
+
icon: "",
|
|
26
|
+
description: "",
|
|
27
|
+
instructions: "",
|
|
28
|
+
model: options.models[0] ?? "",
|
|
29
|
+
tools: usualTools(known, offered),
|
|
30
|
+
});
|
|
31
|
+
const like = (base) => {
|
|
32
|
+
const agent = known[base];
|
|
33
|
+
const model = typeof agent.model === "string" ? agent.model : undefined;
|
|
34
|
+
return {
|
|
35
|
+
name: "",
|
|
36
|
+
icon: agent.icon ?? "",
|
|
37
|
+
description: agent.description ?? "",
|
|
38
|
+
instructions: agent.instructions,
|
|
39
|
+
model: model && options.models.includes(model) ? model : options.models[0] ?? "",
|
|
40
|
+
tools: (agent.tools ?? []).filter((tool) => offered.includes(tool)),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const [from, setFrom] = useState(first && known[first] && !known[first].in ? first : "");
|
|
44
|
+
const [draft, setDraft] = useState(() => from ? like(from) : blank());
|
|
45
|
+
const [role, setRole] = useState("editor");
|
|
46
|
+
const [kind, setKind] = useState(kinds?.[0]?.kind ?? "");
|
|
47
|
+
// Described first, unless it starts from one of the app's agents.
|
|
48
|
+
const [step, setStep] = useState(from ? "form" : "describe");
|
|
49
|
+
const [busy, setBusy] = useState(false);
|
|
50
|
+
const [error, setError] = useState();
|
|
51
|
+
const [made, setMade] = useState();
|
|
52
|
+
const name = draft.name.trim();
|
|
53
|
+
const handle = name ? handleOf(name, (taken) => taken in known) : "";
|
|
54
|
+
const where = placeName(space);
|
|
55
|
+
if (step === "describe" && !made) {
|
|
56
|
+
return (_jsx(Describe, { kinds: kinds, call: call, onSkip: () => setStep("form"), onDraft: (sketch) => {
|
|
57
|
+
setDraft((now) => ({
|
|
58
|
+
...now,
|
|
59
|
+
name: sketch.name,
|
|
60
|
+
icon: sketch.icon,
|
|
61
|
+
description: sketch.description,
|
|
62
|
+
instructions: sketch.instructions,
|
|
63
|
+
}));
|
|
64
|
+
if (sketch.like)
|
|
65
|
+
setKind(sketch.like);
|
|
66
|
+
setStep("form");
|
|
67
|
+
} }));
|
|
68
|
+
}
|
|
69
|
+
if (made) {
|
|
70
|
+
return (_jsx(Done, { made: made, space: space, call: call, again: () => {
|
|
71
|
+
setMade(undefined);
|
|
72
|
+
setFrom("");
|
|
73
|
+
setDraft(blank());
|
|
74
|
+
setStep("describe");
|
|
75
|
+
} }));
|
|
76
|
+
}
|
|
77
|
+
return (_jsxs("form", { className: "agent-new", "aria-label": say("newAgentForm"), onSubmit: async (event) => {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
if (!name || (!kinds?.length && !draft.model) || busy)
|
|
80
|
+
return;
|
|
81
|
+
setBusy(true);
|
|
82
|
+
setError(undefined);
|
|
83
|
+
try {
|
|
84
|
+
const { agent } = await call("agent.create", {
|
|
85
|
+
in: space._id,
|
|
86
|
+
name,
|
|
87
|
+
...(draft.description.trim() ? { description: draft.description.trim() } : {}),
|
|
88
|
+
...(draft.instructions.trim() ? { instructions: draft.instructions.trim() } : {}),
|
|
89
|
+
...(kinds?.length ? (kind ? { like: kind } : {}) : { model: draft.model }),
|
|
90
|
+
tools: draft.tools,
|
|
91
|
+
...(draft.icon ? { icon: draft.icon } : {}),
|
|
92
|
+
...(from ? { from } : {}),
|
|
93
|
+
});
|
|
94
|
+
await call("member.set", {
|
|
95
|
+
space: space._id,
|
|
96
|
+
member: { kind: "agent", id: agent },
|
|
97
|
+
role,
|
|
98
|
+
});
|
|
99
|
+
setMade({ id: agent, ...shownAs(agent, { name, icon: draft.icon || undefined }), role });
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
setError(message(e));
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
setBusy(false);
|
|
106
|
+
}
|
|
107
|
+
}, children: [onBack || app.length
|
|
108
|
+
? (_jsxs("div", { className: "agent-new-top", children: [onBack
|
|
109
|
+
? (_jsx(Button, { size: "sm", variant: "ghost", icon: "chevron-left", onClick: onBack, children: say("agentsYouKnow") }))
|
|
110
|
+
: _jsx("span", {}), app.length
|
|
111
|
+
? (_jsxs("label", { className: "agent-new-from", children: [_jsx("span", { children: say("startFrom") }), _jsxs(Select, { size: "sm", value: from, onChange: (event) => {
|
|
112
|
+
const next = event.target.value;
|
|
113
|
+
setFrom(next);
|
|
114
|
+
setDraft((now) => ({ ...(next ? like(next) : blank()), name: now.name }));
|
|
115
|
+
}, children: [_jsx("option", { value: "", children: say("startBlank") }), app.map(([key, agent]) => (_jsx("option", { value: key, children: shownAs(key, agent).name }, key)))] })] }))
|
|
116
|
+
: null] }))
|
|
117
|
+
: null, _jsx(AgentFields, { value: draft, onChange: (patch) => setDraft((now) => ({ ...now, ...patch })), options: options, handle: handle, call: call, autoFocus: true, model: kinds?.length
|
|
118
|
+
? _jsx(KindField, { kinds: kinds, value: kind, onChange: setKind, disabled: busy })
|
|
119
|
+
: undefined }), _jsx(Field, { label: say("worksInAs", { place: where }), hint: say("belongsHint", {
|
|
120
|
+
lets: AGENT_ROLES.find((r) => r.value === role)?.lets ?? "",
|
|
121
|
+
place: where,
|
|
122
|
+
}), children: (control) => (_jsx(Select, { ...control, value: role, onChange: (event) => setRole(event.target.value), children: AGENT_ROLES.map((r) => _jsx("option", { value: r.value, children: r.label }, r.value)) })) }), _jsxs("div", { className: "agent-new-end", children: [_jsx("p", { id: `${id}-said`, className: "agent-form-note", "aria-live": "polite", children: error ? _jsx("span", { className: "agent-error", role: "alert", children: error }) : null }), _jsx(Button, { type: "submit", variant: "primary", icon: "plus", loading: busy, disabled: !name || (!kinds?.length && !draft.model), "aria-describedby": `${id}-said`, children: name ? say("createNamed", { name }) : say("createAgent") })] })] }));
|
|
123
|
+
}
|
|
124
|
+
/** Made: what it is now, and what's next. */
|
|
125
|
+
function Done({ made, space, call, again }) {
|
|
126
|
+
const [answers, setAnswers] = useState(false);
|
|
127
|
+
const [busy, setBusy] = useState(false);
|
|
128
|
+
const [error, setError] = useState();
|
|
129
|
+
const where = placeName(space);
|
|
130
|
+
return (_jsxs("div", { className: "agent-made", role: "status", children: [_jsxs("span", { className: "agent-made-face", children: [_jsx(Avatar, { name: made.name, kind: "agent", icon: made.icon, size: 48 }), _jsx("span", { className: "agent-made-check", children: _jsx(Icon, { name: "check", size: 12 }) })] }), _jsxs("div", { className: "agent-made-text", children: [_jsx("h3", { children: say("worksNow", { name: made.name, place: where }) }), _jsx("p", { children: error ?? (made.role === "editor"
|
|
131
|
+
? (say.nodes("askHandle", {
|
|
132
|
+
handle: _jsxs("b", { className: "agent-handle", children: ["@", made.id] }),
|
|
133
|
+
}))
|
|
134
|
+
: say("readsOnly")) }), _jsxs("div", { className: "agent-made-actions", children: [made.role === "editor"
|
|
135
|
+
? (_jsx(Button, { size: "sm", icon: answers ? "check" : "chat", loading: busy, disabled: answers, onClick: async () => {
|
|
136
|
+
setBusy(true);
|
|
137
|
+
setError(undefined);
|
|
138
|
+
try {
|
|
139
|
+
await call("space.agent", { space: space._id, agent: made.id });
|
|
140
|
+
setAnswers(true);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
setError(message(e));
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
setBusy(false);
|
|
147
|
+
}
|
|
148
|
+
}, children: answers ? say("answersNewChats") : say("makeAnswer") }))
|
|
149
|
+
: null, _jsx(Button, { size: "sm", href: agentPath(made.id), onClick: leaving, children: say("openPage") }), _jsx(Button, { size: "sm", variant: "ghost", icon: "plus", onClick: again, children: say("makeAnother") })] })] })] }));
|
|
150
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Making an agent for the org's team (kind `agent.org`, hints `{ done?,
|
|
3
|
+
* kinds? }`): for its owners and admins, on the org's page. First what it
|
|
4
|
+
* should do, and Compass drafts the rest (`Describe`, `agent.sketch`), or
|
|
5
|
+
* they fill it in. Then its fields (`AgentFields`), with its kind of work in
|
|
6
|
+
* place of a model where tiers give agents theirs (`kinds`); else a model.
|
|
7
|
+
* Made (`agent.create`, the org's: `in: "*"`), it joins every space in use
|
|
8
|
+
* and every new one; `done()` is called with its id.
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactNode } from "react";
|
|
11
|
+
import type { ViewContext } from "pairz";
|
|
12
|
+
export declare const agentOrgView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Making an agent for the org's team (kind `agent.org`, hints `{ done?,
|
|
4
|
+
* kinds? }`): for its owners and admins, on the org's page. First what it
|
|
5
|
+
* should do, and Compass drafts the rest (`Describe`, `agent.sketch`), or
|
|
6
|
+
* they fill it in. Then its fields (`AgentFields`), with its kind of work in
|
|
7
|
+
* place of a model where tiers give agents theirs (`kinds`); else a model.
|
|
8
|
+
* Made (`agent.create`, the org's: `in: "*"`), it joins every space in use
|
|
9
|
+
* and every new one; `done()` is called with its id.
|
|
10
|
+
*/
|
|
11
|
+
import { useId, useState } from "react";
|
|
12
|
+
import { Button, message, Skeleton } from "pairz/web";
|
|
13
|
+
import { AgentFields } from "./agent-fields.js";
|
|
14
|
+
import { Describe, KindField } from "./agent-describe.js";
|
|
15
|
+
import { handleOf, usualTools } from "./agents.js";
|
|
16
|
+
import { STYLE } from "./style.js";
|
|
17
|
+
import { say } from "./words.js";
|
|
18
|
+
/** The org's own, as the access plugin keeps it: the org itself. */
|
|
19
|
+
const ORG = "*";
|
|
20
|
+
export const agentOrgView = (_, ctx) => {
|
|
21
|
+
const known = ctx.db.collection("agent").query("known", {}).value;
|
|
22
|
+
const options = ctx.db.collection("agent").query("options", {}).value;
|
|
23
|
+
const done = typeof ctx.hints.done === "function"
|
|
24
|
+
? ctx.hints.done
|
|
25
|
+
: undefined;
|
|
26
|
+
const kinds = Array.isArray(ctx.hints.kinds) ? ctx.hints.kinds : undefined;
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsx("style", { href: "team-web", precedence: "pairz", children: STYLE }), known && options
|
|
28
|
+
? _jsx(OrgAgent, { known: known, options: options, kinds: kinds, call: ctx.call, done: done })
|
|
29
|
+
: _jsx(Skeleton, { height: 320, radius: "lg" })] }));
|
|
30
|
+
};
|
|
31
|
+
function OrgAgent({ known, options, kinds, call, done }) {
|
|
32
|
+
const id = useId();
|
|
33
|
+
const offered = options.tools.map((t) => t.name);
|
|
34
|
+
const [step, setStep] = useState("describe");
|
|
35
|
+
const [draft, setDraft] = useState(() => ({
|
|
36
|
+
name: "",
|
|
37
|
+
icon: "",
|
|
38
|
+
description: "",
|
|
39
|
+
instructions: "",
|
|
40
|
+
model: options.models[0] ?? "",
|
|
41
|
+
tools: usualTools(known, offered),
|
|
42
|
+
}));
|
|
43
|
+
const [like, setLike] = useState(kinds?.[0]?.kind ?? "");
|
|
44
|
+
const [busy, setBusy] = useState(false);
|
|
45
|
+
const [error, setError] = useState();
|
|
46
|
+
const name = draft.name.trim();
|
|
47
|
+
const handle = name ? handleOf(name, (taken) => taken in known) : "";
|
|
48
|
+
if (step === "describe") {
|
|
49
|
+
return (_jsx(Describe, { kinds: kinds, call: call, onSkip: () => setStep("form"), onDraft: (sketch) => {
|
|
50
|
+
setDraft((now) => ({
|
|
51
|
+
...now,
|
|
52
|
+
name: sketch.name,
|
|
53
|
+
icon: sketch.icon,
|
|
54
|
+
description: sketch.description,
|
|
55
|
+
instructions: sketch.instructions,
|
|
56
|
+
}));
|
|
57
|
+
if (sketch.like)
|
|
58
|
+
setLike(sketch.like);
|
|
59
|
+
setStep("form");
|
|
60
|
+
} }));
|
|
61
|
+
}
|
|
62
|
+
return (_jsxs("form", { className: "agent-new", "aria-label": say("orgForm"), onSubmit: async (event) => {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
if (!name || busy)
|
|
65
|
+
return;
|
|
66
|
+
setBusy(true);
|
|
67
|
+
setError(undefined);
|
|
68
|
+
try {
|
|
69
|
+
const { agent } = await call("agent.create", {
|
|
70
|
+
in: ORG,
|
|
71
|
+
name,
|
|
72
|
+
...(draft.description.trim() ? { description: draft.description.trim() } : {}),
|
|
73
|
+
...(draft.instructions.trim() ? { instructions: draft.instructions.trim() } : {}),
|
|
74
|
+
tools: draft.tools,
|
|
75
|
+
...(draft.icon ? { icon: draft.icon } : {}),
|
|
76
|
+
...(kinds?.length ? (like ? { like } : {}) : { model: draft.model }),
|
|
77
|
+
});
|
|
78
|
+
done?.(agent);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
setError(message(e));
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
setBusy(false);
|
|
85
|
+
}
|
|
86
|
+
}, children: [_jsx(AgentFields, { value: draft, onChange: (patch) => setDraft((now) => ({ ...now, ...patch })), options: options, handle: handle, call: call, autoFocus: true, model: kinds?.length
|
|
87
|
+
? _jsx(KindField, { kinds: kinds, value: like, onChange: setLike, disabled: busy })
|
|
88
|
+
: undefined }), _jsxs("div", { className: "agent-new-end", children: [_jsx("p", { id: `${id}-said`, className: "agent-form-note", "aria-live": "polite", children: error ? _jsx("span", { className: "agent-error", role: "alert", children: error }) : say("orgJoins") }), _jsx(Button, { variant: "ghost", onClick: () => setStep("describe"), disabled: busy, children: say("back") }), _jsx(Button, { type: "submit", variant: "primary", icon: "plus", loading: busy, disabled: !name, "aria-describedby": `${id}-said`, children: name ? say("addToTeamNamed", { name }) : say("addToTeam") })] })] }));
|
|
89
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What agents offer in the command palette (kind `agent.palette`, the web
|
|
3
|
+
* shell's `palette` resource), for where the person is and what's typed:
|
|
4
|
+
*
|
|
5
|
+
* - **This agent**, on an agent's page: ask it, have it answer new chats
|
|
6
|
+
* where the person is, add it to another space they manage, change it
|
|
7
|
+
* or delete it (those who manage where it belongs).
|
|
8
|
+
* - **This space:** add an agent to it (the invite surface's Agents, in a
|
|
9
|
+
* dialog), for those who manage it; while searching, have one of its
|
|
10
|
+
* agents answer its new chats.
|
|
11
|
+
* - **Agents** to go to (their pages): those working where the person is;
|
|
12
|
+
* while searching, every agent they've met.
|
|
13
|
+
* - **Create:** a new agent, where they are if they manage it, or in a
|
|
14
|
+
* space they pick.
|
|
15
|
+
*/
|
|
16
|
+
import type { ReactNode } from "react";
|
|
17
|
+
import type { ViewContext } from "pairz";
|
|
18
|
+
import { type PaletteGroup } from "pairz/web";
|
|
19
|
+
export declare const agentPaletteView: (_: unknown, ctx: ViewContext<ReactNode>) => PaletteGroup[] | null;
|