@pairz/team 0.0.1 → 1.0.0-rc.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -1
  3. package/WORDS.md +357 -0
  4. package/contract.d.ts +8 -0
  5. package/contract.js +8 -0
  6. package/mod.d.ts +25 -0
  7. package/mod.js +25 -0
  8. package/package.json +61 -3
  9. package/team/actions/agent.d.ts +14 -0
  10. package/team/actions/agent.js +401 -0
  11. package/team/actions/define.d.ts +1 -0
  12. package/team/actions/define.js +45 -0
  13. package/team/collections/agent.d.ts +170 -0
  14. package/team/collections/agent.js +126 -0
  15. package/team/contract.d.ts +11 -0
  16. package/team/contract.js +1 -0
  17. package/team/mod.d.ts +28 -0
  18. package/team/mod.js +64 -0
  19. package/team/resources/propose.d.ts +1 -0
  20. package/team/resources/propose.js +102 -0
  21. package/team/shared/definition.d.ts +3 -0
  22. package/team/shared/definition.js +11 -0
  23. package/team/shared/everywhere.d.ts +11 -0
  24. package/team/shared/everywhere.js +29 -0
  25. package/team/shared/limits.d.ts +17 -0
  26. package/team/shared/limits.js +17 -0
  27. package/team/views/web/agent-add.d.ts +14 -0
  28. package/team/views/web/agent-add.js +58 -0
  29. package/team/views/web/agent-describe.d.ts +38 -0
  30. package/team/views/web/agent-describe.js +44 -0
  31. package/team/views/web/agent-fields.d.ts +35 -0
  32. package/team/views/web/agent-fields.js +88 -0
  33. package/team/views/web/agent-known.d.ts +22 -0
  34. package/team/views/web/agent-known.js +62 -0
  35. package/team/views/web/agent-new.d.ts +27 -0
  36. package/team/views/web/agent-new.js +150 -0
  37. package/team/views/web/agent-org.d.ts +12 -0
  38. package/team/views/web/agent-org.js +89 -0
  39. package/team/views/web/agent-palette.d.ts +19 -0
  40. package/team/views/web/agent-palette.js +203 -0
  41. package/team/views/web/agent-steps.d.ts +23 -0
  42. package/team/views/web/agent-steps.js +56 -0
  43. package/team/views/web/agent.d.ts +20 -0
  44. package/team/views/web/agent.js +310 -0
  45. package/team/views/web/agents.d.ts +48 -0
  46. package/team/views/web/agents.js +59 -0
  47. package/team/views/web/model-pick.d.ts +27 -0
  48. package/team/views/web/model-pick.js +42 -0
  49. package/team/views/web/model-picker.d.ts +57 -0
  50. package/team/views/web/model-picker.js +218 -0
  51. package/team/views/web/places.d.ts +24 -0
  52. package/team/views/web/places.js +10 -0
  53. package/team/views/web/style.d.ts +9 -0
  54. package/team/views/web/style.js +251 -0
  55. package/team/views/web/words.d.ts +5 -0
  56. package/team/views/web/words.js +239 -0
  57. package/team/web.d.ts +22 -0
  58. package/team/web.js +43 -0
  59. package/tiers/actions/choose.d.ts +7 -0
  60. package/tiers/actions/choose.js +315 -0
  61. package/tiers/actions/model.d.ts +1 -0
  62. package/tiers/actions/model.js +60 -0
  63. package/tiers/collections/choice.d.ts +57 -0
  64. package/tiers/collections/choice.js +79 -0
  65. package/tiers/collections/template.d.ts +76 -0
  66. package/tiers/collections/template.js +41 -0
  67. package/tiers/contract.d.ts +23 -0
  68. package/tiers/contract.js +1 -0
  69. package/tiers/mod.d.ts +72 -0
  70. package/tiers/mod.js +111 -0
  71. package/tiers/shared/plans.d.ts +65 -0
  72. package/tiers/shared/plans.js +91 -0
  73. package/tiers/shared/shown.d.ts +187 -0
  74. package/tiers/shared/shown.js +280 -0
  75. package/tiers/shared/tiers.d.ts +150 -0
  76. package/tiers/shared/tiers.js +170 -0
  77. package/tiers/views/web/composer.d.ts +14 -0
  78. package/tiers/views/web/composer.js +81 -0
  79. package/tiers/views/web/org.d.ts +61 -0
  80. package/tiers/views/web/org.js +289 -0
  81. package/tiers/views/web/say.d.ts +139 -0
  82. package/tiers/views/web/say.js +143 -0
  83. package/tiers/views/web/setup.d.ts +23 -0
  84. package/tiers/views/web/setup.js +80 -0
  85. package/tiers/views/web/space.d.ts +31 -0
  86. package/tiers/views/web/space.js +74 -0
  87. package/tiers/views/web/style.d.ts +7 -0
  88. package/tiers/views/web/style.js +191 -0
  89. package/tiers/views/web/team.d.ts +38 -0
  90. package/tiers/views/web/team.js +118 -0
  91. package/tiers/views/web/words.d.ts +48 -0
  92. package/tiers/views/web/words.js +122 -0
  93. package/tiers/web.d.ts +30 -0
  94. package/tiers/web.js +71 -0
  95. package/web.d.ts +14 -0
  96. package/web.js +14 -0
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The tier beside the send button (kind `tiers.composer`, chat's
4
+ * `composerControls`, hints `{ thread?, in? }`): what what's sent runs on,
5
+ * with what a typical message comes to for the person, their own plans
6
+ * costing nothing ("Everyday · on your plans · model $0"). In a
7
+ * conversation, choosing one sets that conversation's tier
8
+ * (`tiers.choose { thread }`), for everyone in it; on home, the person's own
9
+ * default for new chats (`{ mine }`). Each tier says its price; one over the
10
+ * org's cap is out of reach for those who don't run it, and says who sets
11
+ * it. Back to the default where one was chosen.
12
+ */
13
+ import { useState } from "react";
14
+ import { Menu, toast } from "pairz/web";
15
+ import { runs, useStanding } from "pairz/plugins/interfaces/contract";
16
+ import { STYLE } from "./style.js";
17
+ import { say } from "./say.js";
18
+ import { bySaid, shownSaid, tierPriceSaid } from "./words.js";
19
+ export const tiersComposerView = (_, ctx) => {
20
+ const thread = typeof ctx.hints.thread === "string" ? ctx.hints.thread : undefined;
21
+ const space = typeof ctx.hints.in === "string" ? ctx.hints.in : undefined;
22
+ const shown = shownSaid(ctx.db.collection("modelChoice").query("offered", {
23
+ ...(space ? { space } : {}),
24
+ ...(thread ? { thread } : {}),
25
+ }).value);
26
+ if (!shown?.tiers.length || !shown.now)
27
+ return null;
28
+ return (_jsxs(_Fragment, { children: [_jsx("style", { href: "tiers-web", precedence: "pairz", children: STYLE }), _jsx(TierPick, { shown: shown, thread: thread, call: ctx.call })] }));
29
+ };
30
+ function TierPick({ shown, thread, call }) {
31
+ const standing = useStanding(call);
32
+ const [busy, setBusy] = useState(false);
33
+ const free = !!standing && runs(standing);
34
+ const now = shown.now;
35
+ const tier = shown.tiers.find((t) => t.name === now.tier);
36
+ const capIndex = shown.org.cap ? shown.tiers.findIndex((t) => t.name === shown.org.cap) : -1;
37
+ const capTitle = capIndex >= 0 ? shown.tiers[capIndex].title : undefined;
38
+ // What's been chosen right here: the conversation's, or on home the person's own.
39
+ const own = thread ? shown.thread?.tier : shown.person.tier;
40
+ const choose = async (name) => {
41
+ setBusy(true);
42
+ try {
43
+ await call("tiers.choose", { tier: name, ...(thread ? { thread } : { mine: true }) });
44
+ const title = shown.tiers.find((t) => t.name === name)?.title;
45
+ toast(thread
46
+ ? title ? say("chatRunsOn", { tier: title }) : say("chatRunsDefault")
47
+ : title
48
+ ? say("newChatsOn", { tier: title })
49
+ : say("newChatsDefault"));
50
+ }
51
+ catch (e) {
52
+ toast(e.message, { tone: "destructive" });
53
+ }
54
+ finally {
55
+ setBusy(false);
56
+ }
57
+ };
58
+ const items = [
59
+ ...shown.tiers.map((t, i) => {
60
+ const price = tierPriceSaid(t);
61
+ const over = !free && capIndex >= 0 && i > capIndex;
62
+ return {
63
+ label: `${t.title}${price ? ` · ${price}` : ""}`,
64
+ ...(t.name === now.tier ? { icon: "check" } : {}),
65
+ ...(over ? { disabled: true } : {}),
66
+ onSelect: () => void choose(t.name),
67
+ };
68
+ }),
69
+ ...(own
70
+ ? [
71
+ "separator",
72
+ {
73
+ label: thread ? say("backToDefault") : say("backToOrgDefault"),
74
+ onSelect: () => void choose(null),
75
+ },
76
+ ]
77
+ : []),
78
+ ];
79
+ const price = tier && tierPriceSaid(tier);
80
+ return (_jsx("span", { className: "tiers-pick", "aria-busy": busy || undefined, children: _jsx(Menu, { label: `${say("pickLabel", { tier: tier?.title ?? now.tier, by: bySaid(now.by) })}${capTitle && !free ? `. ${say("pickCap", { cap: capTitle })}` : ""}`, text: _jsxs("span", { className: "tiers-pick-text", children: [_jsx("span", { className: "tiers-pick-name", children: tier?.title ?? now.tier }), price ? _jsx("span", { className: "tiers-pick-price", children: ` · ${price}` }) : null] }), icon: "sparkles", variant: "ghost", size: "sm", side: "top", align: "end", items: items }) }));
81
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The org's agents (kind `tiers.org`, the org page's Agents section, the web
3
+ * shell's `orgSettings`, at `/org?tab=models`): how hard they think, then who
4
+ * they are.
5
+ *
6
+ * - **The tiers**, as cards side by side: each its name, what it's good for,
7
+ * what a typical message comes to at this org's prices and how far the
8
+ * plan's credits go, and each kind of work's model; the org's default
9
+ * outlined. Owners and admins make one the default in a click (Undo right
10
+ * after), customize one (a dialog: each kind of work's model and what it
11
+ * falls back to, its name), duplicate one into a new tier, make one from
12
+ * nothing, take one away or put it back as it was, and set the highest
13
+ * tier members may choose. On a plan of credits given once, a heavier
14
+ * default says how much faster it spends them.
15
+ * - **The team** (team.tsx): the agents every space starts with.
16
+ *
17
+ * Anyone else reads it, and is told who changes it. Everything shown is a
18
+ * watched read (`modelChoice.offered`), so a change shows at once.
19
+ */
20
+ import { type ReactNode } from "react";
21
+ import type { ViewContext } from "pairz";
22
+ import type { ModelShown, Shown, TierShown } from "../../contract.js";
23
+ import { type TeamAgent } from "./team.js";
24
+ type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
25
+ export declare const tiersOrgView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
26
+ export declare function OrgAgents({ shown, team, may, org, call }: {
27
+ shown: Shown;
28
+ team?: TeamAgent[];
29
+ may: boolean;
30
+ /** The org's name; none for a person's own. */
31
+ org?: string;
32
+ call: Call;
33
+ }): ReactNode;
34
+ /**
35
+ * What the tier in use means for the plan's credits, when it's worth saying: a
36
+ * plan of credits given once (a trial's) spent faster than the cheapest tier
37
+ * would, or a plan that gives none.
38
+ */
39
+ export declare function SpendNote({ shown, tier }: {
40
+ shown: Shown;
41
+ tier?: string;
42
+ }): ReactNode;
43
+ /** A tier: what it's for, what a message comes to, each kind of work's model, and choosing it. */
44
+ export declare function TierCard({ tier, shown, current, may, busy, onChoose, onEdit, onCopy, onRemove, onRestore }: {
45
+ tier: TierShown;
46
+ shown: Shown;
47
+ /** It's the org's default. */
48
+ current: boolean;
49
+ may: boolean;
50
+ busy?: string;
51
+ onChoose(): void;
52
+ onEdit(): void;
53
+ onCopy(): void;
54
+ onRemove(): void;
55
+ onRestore(): void;
56
+ }): ReactNode;
57
+ /** What a model falls back to, each name once: "GPT-6 Luna, Claude Haiku 5.5". */
58
+ export declare function thenSaid(model: ModelShown): string | undefined;
59
+ /** A model as a short line: "Claude Haiku 5.5, low effort, then GPT-6 Luna". */
60
+ export declare const modelLine: (model: ModelShown) => string;
61
+ export {};
@@ -0,0 +1,289 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The org's agents (kind `tiers.org`, the org page's Agents section, the web
4
+ * shell's `orgSettings`, at `/org?tab=models`): how hard they think, then who
5
+ * they are.
6
+ *
7
+ * - **The tiers**, as cards side by side: each its name, what it's good for,
8
+ * what a typical message comes to at this org's prices and how far the
9
+ * plan's credits go, and each kind of work's model; the org's default
10
+ * outlined. Owners and admins make one the default in a click (Undo right
11
+ * after), customize one (a dialog: each kind of work's model and what it
12
+ * falls back to, its name), duplicate one into a new tier, make one from
13
+ * nothing, take one away or put it back as it was, and set the highest
14
+ * tier members may choose. On a plan of credits given once, a heavier
15
+ * default says how much faster it spends them.
16
+ * - **The team** (team.tsx): the agents every space starts with.
17
+ *
18
+ * Anyone else reads it, and is told who changes it. Everything shown is a
19
+ * watched read (`modelChoice.offered`), so a change shows at once.
20
+ */
21
+ import { useEffect, useState } from "react";
22
+ import { Badge, Button, Card, Dialog, EmptyState, Field, Icon, Input, LazyView, Menu, message, Notice, Select, Skeleton, } from "pairz/web";
23
+ import { runs } from "pairz/plugins/interfaces/contract";
24
+ import { say } from "./say.js";
25
+ import { STYLE } from "./style.js";
26
+ import { Team } from "./team.js";
27
+ import { creditsGo, faster, modelSaid, perReply, providerSaid, shownSaid, unitSaid, } from "./words.js";
28
+ /** How long "Undo" stays after a change. */
29
+ const UNDO_MS = 12_000;
30
+ export const tiersOrgView = (_, ctx) => {
31
+ const shown = shownSaid(ctx.db.collection("modelChoice").query("offered", {}).value);
32
+ // The org's team (team's), when the app lets people make agents.
33
+ const team = ctx.db.collection("agent").query("team", {}).value;
34
+ const may = runs({
35
+ role: ctx.hints.role ?? null,
36
+ staff: ctx.hints.staff === true,
37
+ });
38
+ const org = ctx.hints.org;
39
+ return (_jsxs(_Fragment, { children: [_jsx("style", { href: "tiers-web", precedence: "pairz", children: STYLE }), shown
40
+ ? (_jsx(OrgAgents, { shown: shown, team: team?.agents, may: may, org: org?.kind === "personal" ? undefined : org?.name, call: ctx.call }))
41
+ : _jsx(Loading, {})] }));
42
+ };
43
+ function Loading() {
44
+ return (_jsxs("div", { className: "tiers", "aria-busy": "true", children: [_jsx(Skeleton, { height: 22, width: "55%" }), _jsx("div", { className: "tiers-cards", children: [0, 1, 2, 3].map((n) => _jsx(Skeleton, { height: 300, radius: "xl" }, n)) }), _jsx(Skeleton, { height: 220, radius: "xl" })] }));
45
+ }
46
+ export function OrgAgents({ shown, team, may, org, call }) {
47
+ const [busy, setBusy] = useState();
48
+ const [error, setError] = useState();
49
+ const [done, setDone] = useState();
50
+ const [editing, setEditing] = useState();
51
+ useEffect(() => {
52
+ if (!done)
53
+ return;
54
+ const timer = setTimeout(() => setDone(undefined), UNDO_MS);
55
+ return () => clearTimeout(timer);
56
+ }, [done]);
57
+ if (!shown.tiers.length) {
58
+ return (_jsx(EmptyState, { icon: "bot", title: say("emptyTitle"), children: say("emptyBody") }));
59
+ }
60
+ const fallback = shown.tiers.find((t) => t.name === shown.plan) ?? shown.tiers[0];
61
+ const current = shown.org.tier ?? fallback.name;
62
+ const title = (name) => shown.tiers.find((t) => t.name === name)?.title;
63
+ const act = async (key, work) => {
64
+ setBusy(key);
65
+ setError(undefined);
66
+ try {
67
+ await work();
68
+ }
69
+ catch (e) {
70
+ setError(message(e));
71
+ }
72
+ finally {
73
+ setBusy(undefined);
74
+ }
75
+ };
76
+ const choose = (tier, undoing = false) => act(tier ?? "plan", async () => {
77
+ const before = shown.org.tier;
78
+ await call("tiers.choose", { tier });
79
+ setDone(undoing ? undefined : {
80
+ said: say("doneSaid", { tier: title(tier ?? shown.plan) ?? "" }),
81
+ tier: before,
82
+ });
83
+ });
84
+ return (_jsxs("div", { className: "tiers", children: [_jsxs("div", { className: "tiers-now", children: [_jsxs("p", { children: [say.nodes(shown.org.tier ? "nowOrg" : "nowPlan", { tier: _jsx("b", { children: title(current) }) }), " ", say("nowMore")] }), may && shown.org.tier && shown.plan && shown.org.tier !== shown.plan
85
+ ? (_jsx(Button, { size: "sm", variant: "ghost", loading: busy === "plan", disabled: !!busy, onClick: () => void choose(null), children: say("backToPlan") }))
86
+ : null] }), done
87
+ ? (_jsx(Notice, { tone: "success", role: "status", action: _jsx(Button, { size: "sm", onClick: () => void choose(done.tier, true), disabled: !!busy, children: say("undo") }), children: done.said }))
88
+ : null, error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, may ? null : (_jsx(Notice, { tone: "neutral", icon: "lock", children: org ? say("onlyRunners", { org }) : say("onlyRunnersHere") })), _jsxs("ul", { className: "tiers-cards", "aria-label": say("tiersLabel"), children: [shown.tiers.map((tier) => (_jsx(TierCard, { tier: tier, shown: shown, current: tier.name === current, may: may, busy: busy, onChoose: () => void choose(tier.name), onEdit: () => setEditing({ name: tier.name }), onCopy: () => setEditing({ from: tier.name, title: say("copyOf", { tier: tier.title }) }), onRemove: () => void act(tier.name, () => call("tiers.remove", { tier: tier.name })), onRestore: () => void act(tier.name, () => call("tiers.restore", { tier: tier.name })) }, tier.name))), may
89
+ ? (_jsx("li", { className: "tier-new", children: _jsxs("button", { type: "button", className: "tier-new-button", onClick: () => setEditing({ from: current, title: "" }), children: [_jsx(Icon, { name: "plus", size: 18 }), _jsx("b", { children: say("newTier") }), _jsx("span", { children: say("newTierAbout") })] }) }))
90
+ : null] }), may && shown.removed.length
91
+ ? (_jsxs("p", { className: "tiers-removed", children: [_jsx("span", { children: say("takenAway") }), shown.removed.map((r) => (_jsx(Button, { size: "sm", variant: "ghost", icon: "plus", loading: busy === r.name, onClick: () => void act(r.name, () => call("tiers.restore", { tier: r.name })), children: say("addBackTier", { tier: r.title }) }, r.name)))] }))
92
+ : null, may
93
+ ? (_jsxs("div", { className: "tiers-cap", children: [_jsx("label", { htmlFor: "tiers-cap", children: say("capLabel") }), _jsxs(Select, { id: "tiers-cap", size: "sm", value: shown.org.cap ?? "", disabled: busy === "cap", onChange: (e) => void act("cap", () => call("tiers.cap", { tier: e.target.value || null })), children: [_jsx("option", { value: "", children: say("capAny") }), shown.tiers.map((t) => _jsx("option", { value: t.name, children: t.title }, t.name))] }), _jsx("span", { children: say("capNote") })] }))
94
+ : null, _jsx(SpendNote, { shown: shown, tier: current }), _jsx(Team, { shown: shown, team: team, may: may, org: org, tier: current, call: call }), _jsxs("p", { className: "tiers-foot", children: [_jsx(Icon, { name: "info", size: 14 }), _jsxs("span", { children: [shown.per === "message" ? say("footMessage") : say("footReply"), " ", say.nodes("footPrices", { budget: _jsx("a", { href: "/org?tab=billing", children: say("budget") }) })] })] }), editing
95
+ ? (_jsx(TierEditor, { shown: shown, team: team, editing: editing, call: call, onClose: () => setEditing(undefined) }))
96
+ : null] }));
97
+ }
98
+ /**
99
+ * What the tier in use means for the plan's credits, when it's worth saying: a
100
+ * plan of credits given once (a trial's) spent faster than the cheapest tier
101
+ * would, or a plan that gives none.
102
+ */
103
+ export function SpendNote({ shown, tier }) {
104
+ const credits = shown.credits;
105
+ if (!credits)
106
+ return null;
107
+ if (!credits.amount) {
108
+ return (_jsxs(Notice, { tone: "warning", icon: "info", action: _jsx(Button, { size: "sm", variant: "outline", href: "/org?tab=billing", children: say("billing") }), children: [_jsx("b", { children: say("noCredits", { plan: credits.title }) }), " ", say("noCreditsMore")] }));
109
+ }
110
+ if (credits.every !== "once")
111
+ return null;
112
+ const using = shown.tiers.find((t) => t.name === (tier ?? shown.now?.tier));
113
+ const cheapest = shown.tiers.reduce((low, t) => t.price !== null && (!low || (low.price ?? Infinity) > t.price) ? t : low, undefined);
114
+ if (!using || !cheapest || using.name === cheapest.name)
115
+ return null;
116
+ const times = faster(using.price, cheapest.price);
117
+ if (!times)
118
+ return null;
119
+ const goes = creditsGo(credits, using.price, shown.per);
120
+ return (_jsxs(Notice, { tone: "warning", icon: "info", className: "tiers-spend", children: [_jsx("b", { children: say("faster", { tier: using.title, times, cheapest: cheapest.title }) }), " ", goes ? `${say("fasterGoes", { goes })} ` : "", say("changeAnyTime")] }));
121
+ }
122
+ /** A tier: what it's for, what a message comes to, each kind of work's model, and choosing it. */
123
+ export function TierCard({ tier, shown, current, may, busy, onChoose, onEdit, onCopy, onRemove, onRestore }) {
124
+ const price = perReply(tier.price);
125
+ const goes = creditsGo(shown.credits, tier.price, shown.per);
126
+ const kindTitle = (kind) => shown.kinds.find((k) => k.kind === kind)?.title ?? kind;
127
+ const items = [
128
+ { label: say("customize"), icon: "pencil", onSelect: onEdit },
129
+ { label: say("duplicate"), icon: "copy", onSelect: onCopy },
130
+ ...(tier.changed
131
+ ? [{ label: say("backToOriginal"), icon: "restore", onSelect: onRestore }]
132
+ : []),
133
+ ...(shown.tiers.length > 1
134
+ ? [
135
+ "separator",
136
+ {
137
+ label: tier.made ? say("deleteTier") : say("takeAway"),
138
+ icon: "trash",
139
+ tone: "destructive",
140
+ onSelect: onRemove,
141
+ },
142
+ ]
143
+ : []),
144
+ ];
145
+ return (_jsxs(Card, { as: "li", className: "tier-card", "data-current": current ? true : undefined, "aria-current": current ? "true" : undefined, "aria-labelledby": `tier-${tier.name}`, children: [_jsxs("div", { className: "tier-card-top", children: [_jsx("h3", { id: `tier-${tier.name}`, children: tier.title }), _jsxs("span", { className: "tier-card-badges", children: [current
146
+ ? (_jsxs(Badge, { tone: "primary", children: [_jsx(Icon, { name: "check", size: 12 }), say("badgeDefault")] }))
147
+ : tier.name === shown.plan
148
+ ? _jsx(Badge, { variant: "outline", children: say("badgePlan") })
149
+ : null, tier.made ? _jsx(Badge, { variant: "outline", children: say("badgeYours") }) : null, tier.changed ? _jsx(Badge, { variant: "outline", children: say("badgeChanged") }) : null, may
150
+ ? _jsx(Menu, { label: say("tierMore", { tier: tier.title }), align: "end", items: items })
151
+ : null] })] }), tier.description ? _jsx("p", { className: "tier-card-for", children: tier.description }) : null, _jsx("p", { className: "tier-card-price", children: price
152
+ ? (_jsxs(_Fragment, { children: [_jsx("b", { children: price }), " ", unitSaid(shown.per)] }))
153
+ : say("pricedEach") }), _jsx("p", { className: "tier-card-goes", children: goes ? goes[0].toUpperCase() + goes.slice(1) : null }), _jsx("ul", { className: "tier-card-agents", "aria-label": say("tierModels", { tier: tier.title }), children: tier.kinds.map(({ kind, model }) => (_jsxs("li", { children: [_jsx("span", { className: "tier-who", children: kindTitle(kind) }), _jsxs("span", { className: "tier-model", children: [model.name, thenSaid(model) ? _jsx("small", { children: say("then", { names: thenSaid(model) }) }) : null] })] }, kind))) }), may
154
+ ? (_jsx("div", { className: "tier-card-end", children: current
155
+ ? (_jsxs("p", { className: "tier-card-using", children: [_jsx(Icon, { name: "check", size: 15 }), " ", say("defaultForNew")] }))
156
+ : (_jsx(Button, { loading: busy === tier.name, disabled: !!busy, onClick: onChoose, "aria-describedby": `tier-${tier.name}`, children: say("makeDefault") })) }))
157
+ : null] }));
158
+ }
159
+ const chainOf = (model) => model ? [model.id, ...(model.fallbacks ?? []).map((f) => f.id)] : [];
160
+ /**
161
+ * Customizing a tier, or making one (a dialog): its name and what it's for,
162
+ * then each kind of work, with the agents that do it, its model and what it
163
+ * falls back to (team's picker, `model.pick`), and adding a kind of work of
164
+ * the org's own. Saved at once (`tiers.save`): only the kinds changed.
165
+ */
166
+ function TierEditor({ shown, team, editing, call, onClose }) {
167
+ const tier = editing.name ? shown.tiers.find((t) => t.name === editing.name) : undefined;
168
+ const base = tier ?? shown.tiers.find((t) => t.name === editing.from) ?? shown.tiers[0];
169
+ const making = !tier;
170
+ const [title, setTitle] = useState(tier?.title ?? editing.title ?? "");
171
+ const [description, setDescription] = useState(tier?.description ?? "");
172
+ const [chains, setChains] = useState({});
173
+ const [busy, setBusy] = useState(false);
174
+ const [error, setError] = useState();
175
+ const [adding, setAdding] = useState();
176
+ // Names for models chosen here, until the page shows them.
177
+ const [names, setNames] = useState({});
178
+ const known = new Map();
179
+ for (const t of shown.tiers) {
180
+ for (const k of t.kinds) {
181
+ known.set(k.model.id, k.model.name);
182
+ for (const f of k.model.fallbacks ?? [])
183
+ known.set(f.id, f.name);
184
+ }
185
+ }
186
+ const nameOf = (id) => known.get(id) ?? names[id] ?? id.slice(id.indexOf("/") + 1);
187
+ const chainFor = (kind) => chains[kind] ?? chainOf(base?.kinds.find((k) => k.kind === kind)?.model);
188
+ const set = (kind, chain) => setChains((had) => ({ ...had, [kind]: chain }));
189
+ const agentsOf = (kind) => [
190
+ ...(shown.kinds.find((k) => k.kind === kind)?.agents.map((a) => a.name) ?? []),
191
+ ...(team ?? []).filter((a) => !a.off && a.kind === "org" && a.like === kind).map((a) => a.name),
192
+ ];
193
+ const save = async () => {
194
+ setBusy(true);
195
+ setError(undefined);
196
+ try {
197
+ await call("tiers.save", {
198
+ ...(tier ? { tier: tier.name } : { from: base?.name }),
199
+ ...(title.trim() && title.trim() !== tier?.title ? { title: title.trim() } : {}),
200
+ ...(description.trim() !== (tier?.description ?? "")
201
+ ? { description: description.trim() }
202
+ : {}),
203
+ ...(Object.keys(chains).length ? { kinds: chains } : {}),
204
+ });
205
+ onClose();
206
+ }
207
+ catch (e) {
208
+ setError(message(e));
209
+ setBusy(false);
210
+ }
211
+ };
212
+ const addKind = async () => {
213
+ if (!adding?.title.trim())
214
+ return;
215
+ setBusy(true);
216
+ setError(undefined);
217
+ try {
218
+ await call("tiers.kind", { title: adding.title.trim(), base: adding.base });
219
+ setAdding(undefined);
220
+ }
221
+ catch (e) {
222
+ setError(message(e));
223
+ }
224
+ finally {
225
+ setBusy(false);
226
+ }
227
+ };
228
+ const appKinds = shown.kinds.filter((k) => !k.base);
229
+ return (_jsx(Dialog, { open: true, onClose: onClose, size: "lg", title: making ? say("newTierTitle") : say("customizeTitle", { tier: tier.title }), description: making
230
+ ? say("newTierStarts", { tier: base?.title ?? "" })
231
+ : say("customizeAbout"), footer: _jsxs(_Fragment, { children: [error ? _jsx("span", { className: "tiers-editor-error", role: "alert", children: error }) : null, _jsx(Button, { variant: "ghost", onClick: onClose, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "primary", loading: busy, disabled: making && !title.trim(), onClick: () => void save(), children: making ? say("createTier") : say("save") })] }), children: _jsxs("div", { className: "tiers-editor", children: [_jsxs("div", { className: "tiers-editor-names", children: [_jsx(Field, { label: say("name"), children: (control) => (_jsx(Input, { ...control, value: title, maxLength: 40, placeholder: say("namePlaceholder"), autoFocus: making, onChange: (e) => setTitle(e.target.value) })) }), _jsx(Field, { label: say("forLabel"), children: (control) => (_jsx(Input, { ...control, value: description, maxLength: 200, placeholder: say("forPlaceholder"), onChange: (e) => setDescription(e.target.value) })) })] }), _jsx("ol", { className: "tiers-kinds", children: shown.kinds.map((kind) => {
232
+ const chain = chainFor(kind.kind);
233
+ const who = agentsOf(kind.kind);
234
+ return (_jsxs("li", { className: "tiers-kind", children: [_jsxs("div", { className: "tiers-kind-head", children: [_jsx("b", { children: kind.title }), _jsx("span", { children: who.length ? who.join(", ") : say("nobodyYet") }), chains[kind.kind]
235
+ ? _jsx(Badge, { variant: "outline", children: say("badgeChanged") })
236
+ : null] }), _jsx(ChainEditor, { chain: chain, nameOf: nameOf, onName: (id, name) => setNames((had) => ({ ...had, [id]: name })), onChange: (next) => set(kind.kind, next) })] }, kind.kind));
237
+ }) }), adding
238
+ ? (_jsxs("div", { className: "tiers-kind-new", children: [_jsx(Field, { label: say("newKind"), children: (control) => (_jsx(Input, { ...control, value: adding.title, maxLength: 40, placeholder: say("newKindPlaceholder"), autoFocus: true, onChange: (e) => setAdding({ ...adding, title: e.target.value }) })) }), _jsx(Field, { label: say("startsFrom"), children: (control) => (_jsx(Select, { ...control, value: adding.base, onChange: (e) => setAdding({ ...adding, base: e.target.value }), children: appKinds.map((k) => _jsx("option", { value: k.kind, children: k.title }, k.kind)) })) }), _jsxs("div", { className: "tiers-kind-new-end", children: [_jsx(Button, { size: "sm", variant: "ghost", onClick: () => setAdding(undefined), children: say("cancel") }), _jsx(Button, { size: "sm", variant: "secondary", disabled: !adding.title.trim() || busy, onClick: () => void addKind(), children: say("add") })] })] }))
239
+ : (_jsx(Button, { size: "sm", variant: "ghost", icon: "plus", onClick: () => setAdding({ title: "", base: appKinds[0]?.kind ?? "" }), children: say("addKind") }))] }) }));
240
+ }
241
+ /**
242
+ * A model chain: the model (team's picker), then what's tried when it fails,
243
+ * each with Move up, Move down and Remove, and Add a fallback.
244
+ */
245
+ function ChainEditor({ chain, nameOf, onName, onChange }) {
246
+ const [first, ...rest] = chain;
247
+ const moved = (from, to) => {
248
+ const next = [...rest];
249
+ const [one] = next.splice(from, 1);
250
+ next.splice(to, 0, one);
251
+ return [first, ...next];
252
+ };
253
+ const pick = (onPick) => ({
254
+ onPick: (model) => {
255
+ onName(model, model.slice(model.indexOf("/") + 1));
256
+ onPick(model);
257
+ return Promise.resolve();
258
+ },
259
+ });
260
+ return (_jsxs("div", { className: "tiers-chain", children: [_jsx(LazyView, { kind: "model.pick", item: { value: first ?? "" }, hints: pick((model) => onChange([model, ...rest.filter((id) => id !== model)])), fallback: _jsx(Skeleton, { height: 54 }) }), _jsxs("div", { className: "tiers-fallbacks", children: [_jsx("p", { className: "tiers-fallbacks-head", children: say("fallbacks") }), rest.length
261
+ ? (_jsx("ol", { className: "tiers-fallbacks-list", children: rest.map((id, i) => (_jsxs("li", { children: [_jsxs("span", { className: "tiers-fallback-name", children: [_jsx("b", { children: nameOf(id) }), _jsx("small", { children: providerSaid(id) })] }), _jsx(Menu, { label: say("tierMore", { tier: nameOf(id) }), align: "end", items: [
262
+ ...(i > 0
263
+ ? [{ label: say("moveUp"), onSelect: () => onChange(moved(i, i - 1)) }]
264
+ : []),
265
+ ...(i < rest.length - 1
266
+ ? [{ label: say("moveDown"), onSelect: () => onChange(moved(i, i + 1)) }]
267
+ : []),
268
+ {
269
+ label: say("remove"),
270
+ icon: "trash",
271
+ tone: "destructive",
272
+ onSelect: () => onChange([first, ...rest.filter((_, j) => j !== i)]),
273
+ },
274
+ ] })] }, `${id}:${i}`))) }))
275
+ : _jsx("p", { className: "tiers-fallbacks-none", children: say("noFallback") }), _jsx(LazyView, { kind: "model.pick", item: { value: "" }, hints: {
276
+ ...pick((model) => onChange([first, ...rest.filter((id) => id !== model), model])),
277
+ look: "link",
278
+ label: say("addFallback"),
279
+ disabled: rest.length >= 7,
280
+ }, fallback: null })] })] }));
281
+ }
282
+ /** What a model falls back to, each name once: "GPT-6 Luna, Claude Haiku 5.5". */
283
+ export function thenSaid(model) {
284
+ const names = [...new Set((model.fallbacks ?? []).map((f) => f.name))]
285
+ .filter((name) => name !== model.name);
286
+ return names.length ? names.join(", ") : undefined;
287
+ }
288
+ /** A model as a short line: "Claude Haiku 5.5, low effort, then GPT-6 Luna". */
289
+ export const modelLine = (model) => `${modelSaid(model)}${thenSaid(model) ? `, then ${thenSaid(model)}` : ""}`;
@@ -0,0 +1,139 @@
1
+ /** Every word tiers' web front end shows, to be changed by the app (`tiers.<key>`). */
2
+ import { type Phrase } from "pairz/web/words";
3
+ export declare const tiers: {
4
+ perMessage: string;
5
+ perReply: string;
6
+ messages: {
7
+ one: string;
8
+ other: string;
9
+ };
10
+ replies: {
11
+ one: string;
12
+ other: string;
13
+ };
14
+ creditsOnce: string;
15
+ creditsSeat: string;
16
+ creditsMonth: string;
17
+ underTenth: string;
18
+ effortNone: string;
19
+ effortMinimal: string;
20
+ effortLow: string;
21
+ effortMedium: string;
22
+ effortHigh: string;
23
+ effortXhigh: string;
24
+ effortMax: string;
25
+ effortOther: string;
26
+ providerChatgpt: string;
27
+ byThread: string;
28
+ byPerson: string;
29
+ bySpace: string;
30
+ byOrg: string;
31
+ byPlan: string;
32
+ emptyTitle: string;
33
+ emptyBody: string;
34
+ nowOrg: string;
35
+ nowPlan: string;
36
+ nowMore: string;
37
+ backToPlan: string;
38
+ doneSaid: string;
39
+ undo: string;
40
+ onlyRunners: string;
41
+ onlyRunnersHere: string;
42
+ tiersLabel: string;
43
+ newTier: string;
44
+ newTierAbout: string;
45
+ takenAway: string;
46
+ addBackTier: string;
47
+ capLabel: string;
48
+ capAny: string;
49
+ capNote: string;
50
+ noCredits: string;
51
+ noCreditsMore: string;
52
+ billing: string;
53
+ faster: string;
54
+ fasterGoes: string;
55
+ changeAnyTime: string;
56
+ footMessage: string;
57
+ footReply: string;
58
+ footPrices: string;
59
+ budget: string;
60
+ tierMore: string;
61
+ customize: string;
62
+ duplicate: string;
63
+ copyOf: string;
64
+ backToOriginal: string;
65
+ deleteTier: string;
66
+ takeAway: string;
67
+ badgeDefault: string;
68
+ badgePlan: string;
69
+ badgeYours: string;
70
+ badgeChanged: string;
71
+ pricedEach: string;
72
+ tierModels: string;
73
+ then: string;
74
+ defaultForNew: string;
75
+ makeDefault: string;
76
+ newTierTitle: string;
77
+ customizeTitle: string;
78
+ newTierStarts: string;
79
+ customizeAbout: string;
80
+ cancel: string;
81
+ createTier: string;
82
+ save: string;
83
+ name: string;
84
+ namePlaceholder: string;
85
+ forLabel: string;
86
+ forPlaceholder: string;
87
+ nobodyYet: string;
88
+ newKind: string;
89
+ newKindPlaceholder: string;
90
+ startsFrom: string;
91
+ add: string;
92
+ addKind: string;
93
+ fallbacks: string;
94
+ moveUp: string;
95
+ moveDown: string;
96
+ remove: string;
97
+ noFallback: string;
98
+ addFallback: string;
99
+ teamTitle: string;
100
+ teamAbout: string;
101
+ teamAboutMine: string;
102
+ addAgent: string;
103
+ edit: string;
104
+ removeFromTeam: string;
105
+ badgeOrgs: string;
106
+ onTier: string;
107
+ notOnTeam: string;
108
+ addBack: string;
109
+ addAgentTitle: string;
110
+ addAgentAbout: string;
111
+ addAgentAboutMine: string;
112
+ removeTitle: string;
113
+ removeSaid: string;
114
+ removeSaidMine: string;
115
+ removeDeletes: string;
116
+ removeBack: string;
117
+ recommended: string;
118
+ ownersChoose: string;
119
+ spaceStartsOn: string;
120
+ spaceChosen: string;
121
+ spaceAsOrg: string;
122
+ spaceSwitch: string;
123
+ spaceManagers: string;
124
+ spaceSelect: string;
125
+ asOrg: string;
126
+ agentLine: string;
127
+ onPlans: string;
128
+ pickLabel: string;
129
+ pickCap: string;
130
+ backToDefault: string;
131
+ backToOrgDefault: string;
132
+ chatRunsOn: string;
133
+ chatRunsDefault: string;
134
+ newChatsOn: string;
135
+ newChatsDefault: string;
136
+ };
137
+ export declare const say: import("pairz/web/words").Say<"name" | "then" | "cancel" | "edit" | "namePlaceholder" | "undo" | "add" | "save" | "remove" | "billing" | "fallbacks" | "budget" | "perMessage" | "perReply" | "messages" | "replies" | "creditsOnce" | "creditsSeat" | "creditsMonth" | "underTenth" | "effortNone" | "effortMinimal" | "effortLow" | "effortMedium" | "effortHigh" | "effortXhigh" | "effortMax" | "effortOther" | "providerChatgpt" | "byThread" | "byPerson" | "bySpace" | "byOrg" | "byPlan" | "emptyTitle" | "emptyBody" | "nowOrg" | "nowPlan" | "nowMore" | "backToPlan" | "doneSaid" | "onlyRunners" | "onlyRunnersHere" | "tiersLabel" | "newTier" | "newTierAbout" | "takenAway" | "addBackTier" | "capLabel" | "capAny" | "capNote" | "noCredits" | "noCreditsMore" | "faster" | "fasterGoes" | "changeAnyTime" | "footMessage" | "footReply" | "footPrices" | "tierMore" | "customize" | "duplicate" | "copyOf" | "backToOriginal" | "deleteTier" | "takeAway" | "badgeDefault" | "badgePlan" | "badgeYours" | "badgeChanged" | "pricedEach" | "tierModels" | "defaultForNew" | "makeDefault" | "newTierTitle" | "customizeTitle" | "newTierStarts" | "customizeAbout" | "createTier" | "forLabel" | "forPlaceholder" | "nobodyYet" | "newKind" | "newKindPlaceholder" | "startsFrom" | "addKind" | "moveUp" | "moveDown" | "noFallback" | "addFallback" | "teamTitle" | "teamAbout" | "teamAboutMine" | "addAgent" | "removeFromTeam" | "badgeOrgs" | "onTier" | "notOnTeam" | "addBack" | "addAgentTitle" | "addAgentAbout" | "addAgentAboutMine" | "removeTitle" | "removeSaid" | "removeSaidMine" | "removeDeletes" | "removeBack" | "recommended" | "ownersChoose" | "spaceStartsOn" | "spaceChosen" | "spaceAsOrg" | "spaceSwitch" | "spaceManagers" | "spaceSelect" | "asOrg" | "agentLine" | "onPlans" | "pickLabel" | "pickCap" | "backToDefault" | "backToOrgDefault" | "chatRunsOn" | "chatRunsDefault" | "newChatsOn" | "newChatsDefault">;
138
+ /** Every word of tiers' front end, by area (team's WORDS.md lists them). */
139
+ export declare const PHRASES: Record<string, Record<string, Phrase>>;