@pairz/team 1.0.0-rc.81 → 1.0.0-rc.82

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.
@@ -1,73 +1,52 @@
1
1
  /**
2
2
  * A person's plans, as tiers run them: the app's (providers with `harness`,
3
- * the models plugin's), in the person's order (`harnesses` on their
4
- * `person:<id>` choice: theirs first, then the rest in the app's), and
5
- * those they've connected now (each `connectedPlans` source, asked as them
6
- * on every turn, never kept here), with the models those that said so run.
7
- * A turn's chain goes with them (`{ model, harnesses, served }`), and the
8
- * models plugin runs each model on them first. What a chain would try, in
9
- * order, is `models.check`'s answer.
3
+ * the models plugin's), in one order for everyone (their `order`: a maker's
4
+ * own plan before Cursor), those they've connected now (each
5
+ * `connectedPlans` source, asked as them on every turn, never kept here),
6
+ * with the models those that said so run. A turn's chain goes with them
7
+ * (`{ model, harnesses, served }`), and the models plugin runs each model on
8
+ * them first: whichever subscription of theirs runs a model pays for it,
9
+ * before any credits. What a chain would try, in order, is `models.check`'s
10
+ * answer.
10
11
  */
11
12
  import { personOf } from "pairz";
13
+ import { connectedOf, plansInOrder } from "pairz/plugins/models/contract";
12
14
  import { orgTiersOf } from "./shown.js";
13
- import { personChoice } from "./tiers.js";
14
15
  /** The app's plans, by provider name. */
15
16
  export function harnessesOf(ctx) {
16
17
  const declared = (ctx.resources.provider ?? {});
17
18
  return Object.fromEntries(Object.entries(declared).filter((entry) => !!entry[1]?.harness));
18
19
  }
19
- /** The app's plans in a person's order: theirs first (`mine`), then the rest, lowest `order` first. */
20
- export function orderOf(ctx, mine = []) {
21
- const plans = harnessesOf(ctx);
22
- const byDefault = Object.keys(plans).sort((a, b) => plans[a].harness.order - plans[b].harness.order || a.localeCompare(b));
23
- const theirs = mine.filter((name, i) => plans[name] && mine.indexOf(name) === i);
24
- return [...theirs, ...byDefault.filter((name) => !theirs.includes(name))];
25
- }
26
- /**
27
- * The plans the person a call is for has connected now, as each source says
28
- * (as them), each with the models it said it runs, when it said.
29
- */
30
- export async function connectedOf(ctx) {
31
- const sources = Object.values((ctx.resources.connectedPlans ?? {})).filter((source) => !!source?.action);
32
- const said = await Promise.all(sources.map((source) => ctx.call(source.action, {}).catch(() => [])));
33
- return new Map(said.flat().map((plan) => typeof plan === "string" ? [plan, undefined] : [plan.plan, plan.models]));
34
- }
35
- /** Of `connected` (connectedOf's), the person's plans in their order (`mine`), with their lists. */
36
- export function plansOf(ctx, connected, mine) {
37
- const harnesses = orderOf(ctx, mine).filter((name) => connected.has(name));
20
+ /** Of `connected` (`connectedOf`'s), the person's plans in the plans' order, with their lists. */
21
+ export function plansOf(ctx, connected) {
22
+ const harnesses = plansInOrder(harnessesOf(ctx)).filter((name) => connected.has(name));
38
23
  const served = Object.fromEntries(harnesses.flatMap((name) => connected.get(name) ? [[name, connected.get(name)]] : []));
39
24
  return { harnesses, ...(Object.keys(served).length ? { served } : {}) };
40
25
  }
41
26
  /**
42
- * The plans the person a call is for can run now, in their order (`mine`:
43
- * their `harnesses`), with the models those that said so run: what a model
44
- * list goes with (`{ model, ...plans }`).
27
+ * The plans the person a call is for can run now, in the plans' order, with
28
+ * the models those that said so run: what a model list goes with
29
+ * (`{ model, ...plans }`).
45
30
  */
46
- export async function plansFor(ctx, mine) {
31
+ export async function plansFor(ctx) {
47
32
  if (!personOf(ctx.actor) || !Object.keys(harnessesOf(ctx)).length)
48
33
  return { harnesses: [] };
49
- return plansOf(ctx, await connectedOf(ctx), mine);
34
+ return plansOf(ctx, await connectedOf(ctx));
50
35
  }
51
36
  /**
52
- * The app's plans, as a person orders them: those that run a model some
53
- * tier of the org names (each chain, as it would be tried on every plan, by
54
- * the lists of those they've connected that said one), in their order, each
55
- * with whether they've connected it now, and the first model, in tier order,
56
- * it runs.
37
+ * The app's plans, as Your AI lists them: those that run a model some tier
38
+ * of the org names (each chain, as it would be tried on every plan, by the
39
+ * lists of those they've connected that said one), and those the person has
40
+ * connected, even running none; in the plans' order, each with whether
41
+ * they've connected it now, and the first model it runs.
57
42
  */
58
43
  export async function harnessesShown(ctx) {
59
44
  const plans = harnessesOf(ctx);
60
- const person = personOf(ctx.actor);
61
- if (!person || !Object.keys(plans).length)
45
+ if (!personOf(ctx.actor) || !Object.keys(plans).length)
62
46
  return [];
63
- const all = Object.keys(plans);
64
- const [{ tiers }, mine, connected] = await Promise.all([
65
- orgTiersOf(ctx),
66
- ctx.db.collection("modelChoice").findOne({ _id: personChoice(person) }),
67
- connectedOf(ctx),
68
- ]);
69
- const chains = Object.values(tiers).sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
70
- .flatMap((tier) => Object.values(tier.agents));
47
+ const all = plansInOrder(plans);
48
+ const [{ tiers }, connected] = await Promise.all([orgTiersOf(ctx), connectedOf(ctx)]);
49
+ const chains = Object.values(tiers).flatMap((tier) => Object.values(tier.agents));
71
50
  // Every plan, those that said which models they run by their lists.
72
51
  const { served } = plansOf(ctx, connected);
73
52
  const tried = await Promise.all(chains.map((chain) => ctx.call("models.check", {
@@ -81,11 +60,15 @@ export async function harnessesShown(ctx) {
81
60
  if (!first.has(provider))
82
61
  first.set(provider, id);
83
62
  }
84
- return orderOf(ctx, mine?.harnesses).filter((name) => first.has(name)).map((name) => ({
85
- name,
86
- title: plans[name].title ?? name,
87
- plan: plans[name].harness.plan,
88
- connected: connected.has(name),
89
- model: first.get(name),
90
- }));
63
+ return all.filter((name) => first.has(name) || connected.has(name)).map((name) => {
64
+ const listed = connected.get(name)?.[0];
65
+ const model = first.get(name) ?? (listed ? `${name}/${listed}` : undefined);
66
+ return {
67
+ name,
68
+ title: plans[name].title ?? name,
69
+ plan: plans[name].harness.plan,
70
+ connected: connected.has(name),
71
+ ...(model ? { model } : {}),
72
+ };
73
+ });
91
74
  }
@@ -13,7 +13,7 @@
13
13
  * from the cache (a conversation's history mostly is), and 1,000 out, each
14
14
  * agent's alike, and a tier's price is its agents' average.
15
15
  *
16
- * With the person's plans (`plansFor`: those they can run now, in their
16
+ * With the person's plans (`plansFor`: those they can run now, in the plans'
17
17
  * order, and the models those that said so run), each chain is also priced
18
18
  * as their turns would run it: at the
19
19
  * first model it would try for them (`models.check`, plans first), one of
@@ -125,9 +125,11 @@ export type Shown = {
125
125
  }[];
126
126
  /** The tier the org's plan gives, when the app has plans that say. */
127
127
  plan: string | null;
128
+ /** The org's default, and what its members may use: up to `cap`, or only the default (`fixed`). */
128
129
  org: {
129
130
  tier: string | null;
130
131
  cap: string | null;
132
+ fixed: boolean;
131
133
  };
132
134
  space?: {
133
135
  tier: string | null;
@@ -179,8 +179,8 @@ export async function shownAt(ctx, where = {}) {
179
179
  const ref = entryOf(tier, kind, kinds);
180
180
  return ref === undefined ? [] : [{ ref, agent: kinds[kind].base ?? kind }];
181
181
  }));
182
- // The person's plans they can run now, in their order: what their turns go with.
183
- const theirs = person ? await plansFor(ctx, levels.person?.harnesses) : { harnesses: [] };
182
+ // The person's plans they can run now: what their turns go with.
183
+ const theirs = person ? await plansFor(ctx) : { harnesses: [] };
184
184
  const shown = await modelsShown(ctx, uses, theirs);
185
185
  let cursor = 0;
186
186
  const tiersShown = list.map(([name, tier]) => {
@@ -223,7 +223,11 @@ export async function shownAt(ctx, where = {}) {
223
223
  removed: templates.filter((t) => t.off && app[t._id])
224
224
  .map((t) => ({ name: t._id, title: app[t._id].title })),
225
225
  plan: offered(levels.plan),
226
- org: { tier: offered(levels.org?.tier), cap: offered(levels.org?.cap) },
226
+ org: {
227
+ tier: offered(levels.org?.tier),
228
+ cap: offered(levels.org?.cap),
229
+ fixed: levels.org?.fixed === true,
230
+ },
227
231
  ...(where.space ? { space: { tier: offered(levels.space?.tier) } } : {}),
228
232
  ...(where.thread ? { thread: { tier: offered(levels.thread?.tier) } } : {}),
229
233
  person: { tier: offered(levels.person?.tier) },
@@ -16,7 +16,10 @@
16
16
  * base kind's chain there.
17
17
  * - **Which tier a turn uses**, the first that applies: the conversation's,
18
18
  * the person's own default for new chats, the space's, the org's, the
19
- * plan's (`modelChoice`).
19
+ * plan's (`modelChoice`); only the org's and the plan's when the org uses
20
+ * its default alone (`fixed`).
21
+ * - **In order:** the app's tiers by their `order`, an org's own order over
22
+ * it (`tiers.order`); a cap is "up to" a tier in that order.
20
23
  */
21
24
  import type { Resources } from "pairz";
22
25
  import type { ModelRef } from "pairz/plugins/models/contract";
@@ -64,13 +67,13 @@ export type OrgKind = {
64
67
  at: string;
65
68
  };
66
69
  /**
67
- * What a level chose: a tier by its name; the org's also the highest tier its
68
- * members may use; a person's also the order of their plans (`harnesses`).
70
+ * What a level chose: a tier by its name; the org's also what its members
71
+ * may use: tiers up to one (`cap`), or only its default (`fixed`).
69
72
  */
70
73
  export type Choice = {
71
74
  tier?: string;
72
75
  cap?: string;
73
- harnesses?: string[];
76
+ fixed?: boolean;
74
77
  };
75
78
  /** Where a choice is kept. */
76
79
  export declare const ORG_CHOICE = "org";
@@ -113,7 +116,11 @@ export declare function tiersIn(ctx: {
113
116
  }, templates: Template[]): Record<string, OrgTier>;
114
117
  /** A kind's chain in a tier: its own entry there, else its base kind's. */
115
118
  export declare function entryOf(tier: Tier | undefined, kind: string | undefined, kinds: Record<string, Kind>): ModelRef | undefined;
116
- /** The tier in force, and who chose it: the conversation, the person, the space, the org, the plan. */
119
+ /**
120
+ * The tier in force, and who chose it: the conversation, the person, the
121
+ * space, the org, the plan; only the org and the plan where the org uses its
122
+ * default alone (`fixed`).
123
+ */
117
124
  export declare function tierIn(tiers: Record<string, unknown>, levels: Levels): {
118
125
  tier: string;
119
126
  by: By;
@@ -60,6 +60,8 @@ export function tiersIn(ctx, templates) {
60
60
  mine.title !== undefined || mine.description !== undefined);
61
61
  out.push([name, {
62
62
  ...tier,
63
+ // The org's place for it, over the app's.
64
+ ...(mine?.order !== undefined ? { order: mine.order } : {}),
63
65
  ...(mine?.title ? { title: mine.title } : {}),
64
66
  ...(mine?.description !== undefined ? { description: mine.description } : {}),
65
67
  agents: { ...tier.agents, ...mine?.agents },
@@ -89,11 +91,18 @@ export function entryOf(tier, kind, kinds) {
89
91
  const base = kinds[kind]?.base;
90
92
  return base && tier.agents[base] !== undefined ? tier.agents[base] : undefined;
91
93
  }
94
+ /** The levels that choose a tier, first first, above the plan's. */
95
+ const LEVELS = ["thread", "person", "space", "org"];
92
96
  /** A tier that's still offered: one that's gone counts as none chosen. */
93
97
  const offered = (tiers, name) => name && Object.hasOwn(tiers, name) ? name : undefined;
94
- /** The tier in force, and who chose it: the conversation, the person, the space, the org, the plan. */
98
+ /**
99
+ * The tier in force, and who chose it: the conversation, the person, the
100
+ * space, the org, the plan; only the org and the plan where the org uses its
101
+ * default alone (`fixed`).
102
+ */
95
103
  export function tierIn(tiers, levels) {
96
- for (const by of ["thread", "person", "space", "org"]) {
104
+ const levelsNow = levels.org?.fixed ? ["org"] : LEVELS;
105
+ for (const by of levelsNow) {
97
106
  const tier = offered(tiers, levels[by]?.tier);
98
107
  if (tier)
99
108
  return { tier, by };
@@ -7,7 +7,8 @@
7
7
  * (`tiers.choose { thread }`), for everyone in it; on home, the person's own
8
8
  * default for new chats (`{ mine }`). Each tier says its price; one over the
9
9
  * org's cap is out of reach for those who don't run it, and says who sets
10
- * it. Back to the default where one was chosen.
10
+ * it. Back to the default where one was chosen. Where the org uses only its
11
+ * default, it just says the tier: there's nothing to switch.
11
12
  */
12
13
  import { type ReactNode } from "react";
13
14
  import type { ViewContext } from "pairz";
@@ -8,7 +8,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
8
8
  * (`tiers.choose { thread }`), for everyone in it; on home, the person's own
9
9
  * default for new chats (`{ mine }`). Each tier says its price; one over the
10
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.
11
+ * it. Back to the default where one was chosen. Where the org uses only its
12
+ * default, it just says the tier: there's nothing to switch.
12
13
  */
13
14
  import { useState } from "react";
14
15
  import { Menu, toast } from "pairz/web";
@@ -77,5 +78,10 @@ function TierPick({ shown, thread, call }) {
77
78
  : []),
78
79
  ];
79
80
  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
+ const 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] }));
82
+ // Only the default: the tier, said, with nothing to choose.
83
+ if (shown.org.fixed) {
84
+ return (_jsx("span", { className: "tiers-pick", "data-fixed": "", title: say("capDefaultNote"), children: text }));
85
+ }
86
+ 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: text, icon: "sparkles", variant: "ghost", size: "sm", side: "top", align: "end", items: items }) }));
81
87
  }
@@ -3,15 +3,17 @@
3
3
  * shell's `orgSettings`, at `/org?tab=models`): how hard they think, then who
4
4
  * they are.
5
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.
6
+ * - **The tiers**, as cards side by side, in the org's order: each its name,
7
+ * what it's good for, what a typical message comes to at this org's prices
8
+ * and how far the plan's credits go, and each kind of work's model; the
9
+ * org's default outlined. Owners and admins make one the default in a
10
+ * click (Undo right after), customize one (a dialog: each kind of work's
11
+ * models in the order they're tried, any of them first, from every model
12
+ * the org can run, each saying how it's paid for), duplicate one into a
13
+ * new tier, make one from nothing, move one before or after another, take
14
+ * one away or put it back as it was, and say what members can use (all
15
+ * tiers, up to one, or only the default). On a plan of credits given once,
16
+ * a heavier default says how much faster it spends them.
15
17
  * - **The team** (team.tsx): the agents every space starts with.
16
18
  *
17
19
  * Anyone else reads it, and is told who changes it. Everything shown is a
@@ -23,14 +25,18 @@ import type { ModelShown, Shown, TierShown } from "../../contract.js";
23
25
  import { type TeamAgent } from "./team.js";
24
26
  type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
25
27
  export declare const tiersOrgView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
26
- export declare function OrgAgents({ shown, team, may, org, call }: {
28
+ export declare function OrgAgents({ shown, team, may, org, personal, call }: {
27
29
  shown: Shown;
28
30
  team?: TeamAgent[];
29
31
  may: boolean;
30
32
  /** The org's name; none for a person's own. */
31
33
  org?: string;
34
+ /** A person's own org: its tiers' models are theirs alone. */
35
+ personal?: boolean;
32
36
  call: Call;
33
37
  }): ReactNode;
38
+ /** A list with one entry moved from `from` to `to`. */
39
+ export declare function moved<T>(list: T[], from: number, to: number): T[];
34
40
  /**
35
41
  * What the tier in use means for the plan's credits, when it's worth saying: a
36
42
  * plan of credits given once (a trial's) spent faster than the cheapest tier
@@ -41,7 +47,7 @@ export declare function SpendNote({ shown, tier }: {
41
47
  tier?: string;
42
48
  }): ReactNode;
43
49
  /** 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 }: {
50
+ export declare function TierCard({ tier, shown, current, may, busy, onChoose, onEdit, onCopy, onMove, onRemove, onRestore }: {
45
51
  tier: TierShown;
46
52
  shown: Shown;
47
53
  /** It's the org's default. */
@@ -51,6 +57,8 @@ export declare function TierCard({ tier, shown, current, may, busy, onChoose, on
51
57
  onChoose(): void;
52
58
  onEdit(): void;
53
59
  onCopy(): void;
60
+ /** Moves it before the one before it (-1), or after the one after it (1). */
61
+ onMove?(by: -1 | 1): void;
54
62
  onRemove(): void;
55
63
  onRestore(): void;
56
64
  }): ReactNode;
@@ -4,15 +4,17 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
4
4
  * shell's `orgSettings`, at `/org?tab=models`): how hard they think, then who
5
5
  * they are.
6
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.
7
+ * - **The tiers**, as cards side by side, in the org's order: each its name,
8
+ * what it's good for, what a typical message comes to at this org's prices
9
+ * and how far the plan's credits go, and each kind of work's model; the
10
+ * org's default outlined. Owners and admins make one the default in a
11
+ * click (Undo right after), customize one (a dialog: each kind of work's
12
+ * models in the order they're tried, any of them first, from every model
13
+ * the org can run, each saying how it's paid for), duplicate one into a
14
+ * new tier, make one from nothing, move one before or after another, take
15
+ * one away or put it back as it was, and say what members can use (all
16
+ * tiers, up to one, or only the default). On a plan of credits given once,
17
+ * a heavier default says how much faster it spends them.
16
18
  * - **The team** (team.tsx): the agents every space starts with.
17
19
  *
18
20
  * Anyone else reads it, and is told who changes it. Everything shown is a
@@ -37,13 +39,13 @@ export const tiersOrgView = (_, ctx) => {
37
39
  });
38
40
  const org = ctx.hints.org;
39
41
  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 }))
42
+ ? (_jsx(OrgAgents, { shown: shown, team: team?.agents, may: may, org: org?.kind === "personal" ? undefined : org?.name, personal: org?.kind === "personal", call: ctx.call }))
41
43
  : _jsx(Loading, {})] }));
42
44
  };
43
45
  function Loading() {
44
46
  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
47
  }
46
- export function OrgAgents({ shown, team, may, org, call }) {
48
+ export function OrgAgents({ shown, team, may, org, personal, call }) {
47
49
  const [busy, setBusy] = useState();
48
50
  const [error, setError] = useState();
49
51
  const [done, setDone] = useState();
@@ -81,20 +83,42 @@ export function OrgAgents({ shown, team, may, org, call }) {
81
83
  tier: before,
82
84
  });
83
85
  });
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
86
+ 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) }) }), " ", shown.org.fixed ? say("capDefaultNote") : say("nowMore")] }), may && shown.org.tier && shown.plan && shown.org.tier !== shown.plan
85
87
  ? (_jsx(Button, { size: "sm", variant: "ghost", loading: busy === "plan", disabled: !!busy, onClick: () => void choose(null), children: say("backToPlan") }))
86
88
  : null] }), done
87
89
  ? (_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
90
+ : null, error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, may ? null : (_jsx(Notice, { tone: "neutral", icon: "lock", children: shown.org.fixed
91
+ ? say("onlyRunnersFixed")
92
+ : org
93
+ ? say("onlyRunners", { org })
94
+ : say("onlyRunnersHere") })), _jsxs("ul", { className: "tiers-cards", "aria-label": say("tiersLabel"), children: [shown.tiers.map((tier, i) => (_jsx(TierCard, { tier: tier, shown: shown, current: tier.name === current, may: may, busy: busy, onMove: (by) => void act(tier.name, () => call("tiers.order", { tiers: moved(shown.tiers.map((t) => t.name), i, i + by) })), 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
95
  ? (_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
96
  : null] }), may && shown.removed.length
91
97
  ? (_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) }))
98
+ : null, may ? _jsx(MembersUse, { shown: shown, busy: busy, act: act, call: call }) : 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
99
+ ? (_jsx(TierEditor, { shown: shown, team: team, editing: editing, members: !personal, call: call, onClose: () => setEditing(undefined) }))
96
100
  : null] }));
97
101
  }
102
+ /** A list with one entry moved from `from` to `to`. */
103
+ export function moved(list, from, to) {
104
+ const next = [...list];
105
+ const [one] = next.splice(from, 1);
106
+ next.splice(to, 0, one);
107
+ return next;
108
+ }
109
+ /**
110
+ * What the org's members can use, in one choice: every tier, tiers up to
111
+ * one (in the org's order), or only the org's default (`tiers.cap`).
112
+ */
113
+ function MembersUse({ shown, busy, act, call }) {
114
+ // Up to the last is every tier.
115
+ const cap = shown.org.cap !== shown.tiers.at(-1)?.name ? shown.org.cap : null;
116
+ const value = shown.org.fixed ? "default" : cap ? `up:${cap}` : "all";
117
+ const set = (next) => act("cap", () => call("tiers.cap", next === "default"
118
+ ? { fixed: true }
119
+ : { tier: next.startsWith("up:") ? next.slice(3) : null }));
120
+ return (_jsxs("div", { className: "tiers-cap", children: [_jsx("label", { htmlFor: "tiers-cap", children: say("capLabel") }), _jsxs(Select, { id: "tiers-cap", size: "sm", value: value, disabled: busy === "cap", onChange: (e) => void set(e.target.value), children: [_jsx("option", { value: "all", children: say("capAll") }), shown.tiers.slice(0, -1).map((t) => (_jsx("option", { value: `up:${t.name}`, children: say("capUpTo", { tier: t.title }) }, t.name))), _jsx("option", { value: "default", children: say("capDefault") })] }), _jsx("span", { children: shown.org.fixed ? say("capDefaultNote") : say("capNote") })] }));
121
+ }
98
122
  /**
99
123
  * What the tier in use means for the plan's credits, when it's worth saying: a
100
124
  * plan of credits given once (a trial's) spent faster than the cheapest tier
@@ -120,13 +144,30 @@ export function SpendNote({ shown, tier }) {
120
144
  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
145
  }
122
146
  /** 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 }) {
147
+ export function TierCard({ tier, shown, current, may, busy, onChoose, onEdit, onCopy, onMove, onRemove, onRestore }) {
124
148
  const price = perReply(tier.price);
125
149
  const goes = creditsGo(shown.credits, tier.price, shown.per);
126
150
  const kindTitle = (kind) => shown.kinds.find((k) => k.kind === kind)?.title ?? kind;
151
+ const at = shown.tiers.findIndex((t) => t.name === tier.name);
152
+ const before = shown.tiers[at - 1];
153
+ const after = shown.tiers[at + 1];
127
154
  const items = [
128
155
  { label: say("customize"), icon: "pencil", onSelect: onEdit },
129
156
  { label: say("duplicate"), icon: "copy", onSelect: onCopy },
157
+ ...(onMove && before
158
+ ? [{
159
+ label: say("moveBefore", { tier: before.title }),
160
+ icon: "chevron-left",
161
+ onSelect: () => onMove(-1),
162
+ }]
163
+ : []),
164
+ ...(onMove && after
165
+ ? [{
166
+ label: say("moveAfter", { tier: after.title }),
167
+ icon: "chevron",
168
+ onSelect: () => onMove(1),
169
+ }]
170
+ : []),
130
171
  ...(tier.changed
131
172
  ? [{ label: say("backToOriginal"), icon: "restore", onSelect: onRestore }]
132
173
  : []),
@@ -160,10 +201,13 @@ const chainOf = (model) => model ? [model.id, ...(model.fallbacks ?? []).map((f)
160
201
  /**
161
202
  * Customizing a tier, or making one (a dialog): its name and what it's for,
162
203
  * 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.
204
+ * falls back to (team's picker, `model.pick`, offering every model the org
205
+ * can run, each saying how it's paid for: `members`, for an org of others,
206
+ * that those without a model's plan fall back to the next), and adding a
207
+ * kind of work of the org's own. Saved at once (`tiers.save`): only the
208
+ * kinds changed.
165
209
  */
166
- function TierEditor({ shown, team, editing, call, onClose }) {
210
+ function TierEditor({ shown, team, editing, members, call, onClose }) {
167
211
  const tier = editing.name ? shown.tiers.find((t) => t.name === editing.name) : undefined;
168
212
  const base = tier ?? shown.tiers.find((t) => t.name === editing.from) ?? shown.tiers[0];
169
213
  const making = !tier;
@@ -233,24 +277,20 @@ function TierEditor({ shown, team, editing, call, onClose }) {
233
277
  const who = agentsOf(kind.kind);
234
278
  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
279
  ? _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));
280
+ : null] }), _jsx(ChainEditor, { chain: chain, members: members, nameOf: nameOf, onName: (id, name) => setNames((had) => ({ ...had, [id]: name })), onChange: (next) => set(kind.kind, next) })] }, kind.kind));
237
281
  }) }), adding
238
282
  ? (_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
283
  : (_jsx(Button, { size: "sm", variant: "ghost", icon: "plus", onClick: () => setAdding({ title: "", base: appKinds[0]?.kind ?? "" }), children: say("addKind") }))] }) }));
240
284
  }
241
285
  /**
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.
286
+ * A model chain, in the order it's tried: the model (team's picker), then
287
+ * what's tried when it fails, each with Move up (the first of them up to the
288
+ * model's place: "Try it first"), Move down and Remove, and Add a fallback.
244
289
  */
245
- function ChainEditor({ chain, nameOf, onName, onChange }) {
290
+ function ChainEditor({ chain, members, nameOf, onName, onChange }) {
246
291
  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
292
  const pick = (onPick) => ({
293
+ plans: members ? "members" : "mine",
254
294
  onPick: (model) => {
255
295
  onName(model, model.slice(model.indexOf("/") + 1));
256
296
  onPick(model);
@@ -259,11 +299,16 @@ function ChainEditor({ chain, nameOf, onName, onChange }) {
259
299
  });
260
300
  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
301
  ? (_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
- : []),
302
+ // In the chain, it's at i + 1: up to i, the model's place for the first.
303
+ {
304
+ label: i === 0 ? say("tryFirst") : say("moveUp"),
305
+ onSelect: () => onChange(moved(chain, i + 1, i)),
306
+ },
265
307
  ...(i < rest.length - 1
266
- ? [{ label: say("moveDown"), onSelect: () => onChange(moved(i, i + 1)) }]
308
+ ? [{
309
+ label: say("moveDown"),
310
+ onSelect: () => onChange(moved(chain, i + 1, i + 2)),
311
+ }]
267
312
  : []),
268
313
  {
269
314
  label: say("remove"),
@@ -39,14 +39,18 @@ export declare const tiers: {
39
39
  undo: string;
40
40
  onlyRunners: string;
41
41
  onlyRunnersHere: string;
42
+ onlyRunnersFixed: string;
42
43
  tiersLabel: string;
43
44
  newTier: string;
44
45
  newTierAbout: string;
45
46
  takenAway: string;
46
47
  addBackTier: string;
47
48
  capLabel: string;
48
- capAny: string;
49
+ capAll: string;
50
+ capUpTo: string;
51
+ capDefault: string;
49
52
  capNote: string;
53
+ capDefaultNote: string;
50
54
  noCredits: string;
51
55
  noCreditsMore: string;
52
56
  billing: string;
@@ -60,6 +64,8 @@ export declare const tiers: {
60
64
  tierMore: string;
61
65
  customize: string;
62
66
  duplicate: string;
67
+ moveBefore: string;
68
+ moveAfter: string;
63
69
  copyOf: string;
64
70
  backToOriginal: string;
65
71
  deleteTier: string;
@@ -91,6 +97,7 @@ export declare const tiers: {
91
97
  add: string;
92
98
  addKind: string;
93
99
  fallbacks: string;
100
+ tryFirst: string;
94
101
  moveUp: string;
95
102
  moveDown: string;
96
103
  remove: string;
@@ -134,6 +141,6 @@ export declare const tiers: {
134
141
  newChatsOn: string;
135
142
  newChatsDefault: string;
136
143
  };
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">;
144
+ 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" | "onlyRunnersFixed" | "tiersLabel" | "newTier" | "newTierAbout" | "takenAway" | "addBackTier" | "capLabel" | "capAll" | "capUpTo" | "capDefault" | "capNote" | "capDefaultNote" | "noCredits" | "noCreditsMore" | "faster" | "fasterGoes" | "changeAnyTime" | "footMessage" | "footReply" | "footPrices" | "tierMore" | "customize" | "duplicate" | "moveBefore" | "moveAfter" | "copyOf" | "backToOriginal" | "deleteTier" | "takeAway" | "badgeDefault" | "badgePlan" | "badgeYours" | "badgeChanged" | "pricedEach" | "tierModels" | "defaultForNew" | "makeDefault" | "newTierTitle" | "customizeTitle" | "newTierStarts" | "customizeAbout" | "createTier" | "forLabel" | "forPlaceholder" | "nobodyYet" | "newKind" | "newKindPlaceholder" | "startsFrom" | "addKind" | "tryFirst" | "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
145
  /** Every word of tiers' front end, by area (team's WORDS.md lists them). */
139
146
  export declare const PHRASES: Record<string, Record<string, Phrase>>;