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

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,10 +1,12 @@
1
1
  /**
2
2
  * Which tier applies where (`modelChoice`): the org's (`_id: "org"`, with
3
3
  * what its members may use: `cap`, the highest tier they may choose, or
4
- * `fixed`, only its default), a space's (`space:<id>`), a conversation's
4
+ * `fixed`, only its default; and `plansFirst`, their subscriptions used
5
+ * whenever possible), a space's (`space:<id>`), a conversation's
5
6
  * (`thread:<id>`) and a person's own default for new chats (`person:<id>`).
6
7
  * Each a tier by its name, never a copy: changing a tier moves everyone on
7
- * it. Changed only through `tiers.choose` and `tiers.cap`, which say who
8
+ * it. Changed only through `tiers.choose`, `tiers.cap` and
9
+ * `tiers.plansFirst`, which say who
8
10
  * may; read by `_id`, so a turn's asking costs what the owner has cached. A
9
11
  * person's choice saved when people ordered their plans may still hold
10
12
  * `harnesses`: nothing reads it, and their next choice drops it.
@@ -38,6 +40,12 @@ const choiceSchema = {
38
40
  cap: { type: "string" },
39
41
  /** The org's: its members use only its default; no space, conversation or person chooses. */
40
42
  fixed: { type: "boolean" },
43
+ /**
44
+ * The org's: every model of a chain on a member's plans before any on
45
+ * credits, then the tier's fallbacks on their plans; none: model by
46
+ * model, in the tier's order.
47
+ */
48
+ plansFirst: { type: "boolean" },
41
49
  at: { type: "string" },
42
50
  },
43
51
  required: ["at"],
@@ -8,6 +8,7 @@ export declare const tierTemplate: Omit<import("pairz").CollectionDef, "schema"
8
8
  [x: string]: unknown;
9
9
  } | undefined;
10
10
  order?: number | undefined;
11
+ fallbacks?: unknown[] | undefined;
11
12
  made?: boolean | undefined;
12
13
  at: string;
13
14
  }>>> | undefined;
@@ -28,6 +29,10 @@ export declare const tierTemplate: Omit<import("pairz").CollectionDef, "schema"
28
29
  readonly agents: {
29
30
  readonly type: "object";
30
31
  };
32
+ /** Models tried on members' plans after any chain, where the org says (`plansFirst`). */
33
+ readonly fallbacks: {
34
+ readonly type: "array";
35
+ };
31
36
  readonly off: {
32
37
  readonly type: "boolean";
33
38
  };
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * The org's tiers, as it keeps them (`tierTemplate`, one per tier, by its
3
- * name): its version of one of the app's (kinds' chains changed, a title, its
4
- * place among them, or `off`: taken away), or one it made (`made`, whole).
3
+ * name): its version of one of the app's (kinds' chains changed, its
4
+ * fallbacks on members' plans, a title, its place among them, or `off`: taken
5
+ * away), or one it made (`made`, whole).
5
6
  * Changed only through `tiers.save`, `tiers.order`, `tiers.remove` and
6
7
  * `tiers.restore`, by the org's owners and admins; everyone in the org reads
7
8
  * them, through `modelChoice.offered`.
@@ -16,6 +17,8 @@ export const tierTemplate = defineCollection({
16
17
  order: { type: "number" },
17
18
  /** Kinds of work's chains, by kind. */
18
19
  agents: { type: "object" },
20
+ /** Models tried on members' plans after any chain, where the org says (`plansFirst`). */
21
+ fallbacks: { type: "array" },
19
22
  off: { type: "boolean" },
20
23
  made: { type: "boolean" },
21
24
  at: { type: "string" },
@@ -6,8 +6,8 @@
6
6
  * reached by name: its collections (`modelChoice`, `tierTemplate`,
7
7
  * `tierKind`), its queries (`modelChoice.offered`, `modelChoice.agent`,
8
8
  * `modelChoice.harnesses`) and its Actions (`tiers.model`, `tiers.choose`,
9
- * `tiers.cap`, `tiers.save`, `tiers.order`, `tiers.remove`, `tiers.restore`,
10
- * `tiers.kind`).
9
+ * `tiers.cap`, `tiers.plansFirst`, `tiers.save`, `tiers.order`,
10
+ * `tiers.remove`, `tiers.restore`, `tiers.kind`).
11
11
  */
12
12
  export type { By, Choice, Kind, Tier } from "./shared/tiers.js";
13
13
  export type { HarnessShown } from "./shared/plans.js";
package/tiers/mod.d.ts CHANGED
@@ -27,16 +27,19 @@
27
27
  * - **Every turn:** chat asks `tiers.model` through its `agentModel` resource,
28
28
  * for every agent, with the kind it works like. A change applies from each
29
29
  * conversation's next reply.
30
- * - **Plans first:** where the app has people's plans (providers with
30
+ * - **On people's plans:** where the app has people's plans (providers with
31
31
  * `harness`: Claude Code, ChatGPT…), a turn's chain goes with the plans its
32
32
  * person has connected now (each `connectedPlans` source says), in one
33
33
  * order for everyone (theirs: a maker's own plan before Cursor;
34
- * `modelChoice.harnesses` lists them), and each model runs on those that
35
- * serve it before any API, so a subscription pays for every model it runs,
36
- * before credits: by the models a plan said it runs, where it said
37
- * (`served`). A tier names models; an entry naming a plan (`claude-plan/…`)
38
- * stands for its model on plans only. `plansFor` (shared/plans.ts) is what
39
- * a turn goes with, and `models.check` what a chain would try.
34
+ * `modelChoice.harnesses` lists them), by the models a plan said it runs,
35
+ * where it said (`served`). The tier's models run in its order, each on
36
+ * their plans that run it, then on credits. An org that wants members'
37
+ * subscriptions used whenever possible says so (`tiers.plansFirst`): every
38
+ * model on their plans before any on credits, then the tier's `fallbacks`
39
+ * (one model per maker) on their plans only. A tier names models; an
40
+ * entry naming a plan (`claude-plan/…`) stands for its model on plans
41
+ * only. `plansFor` (shared/plans.ts) is what a turn goes with, and
42
+ * `models.check` what a chain would try.
40
43
  *
41
44
  * Its queries (`modelChoice.offered`, `modelChoice.agent`) show the tiers
42
45
  * with what a typical message comes to at the org's prices (the app's
@@ -63,6 +66,8 @@
63
66
  * north: [{ model: "anthropic/claude-opus-5-5", effort: "medium" }, "openai/gpt-6.1-sol"],
64
67
  * east: { model: "anthropic/claude-sonnet-5-5", effort: "high" },
65
68
  * },
69
+ * // On members' plans only, where the org uses them whenever possible.
70
+ * fallbacks: ["anthropic/claude-opus-5-5", "openai/gpt-6.2-sol"],
66
71
  * },
67
72
  * },
68
73
  * },
package/tiers/mod.js CHANGED
@@ -27,16 +27,19 @@
27
27
  * - **Every turn:** chat asks `tiers.model` through its `agentModel` resource,
28
28
  * for every agent, with the kind it works like. A change applies from each
29
29
  * conversation's next reply.
30
- * - **Plans first:** where the app has people's plans (providers with
30
+ * - **On people's plans:** where the app has people's plans (providers with
31
31
  * `harness`: Claude Code, ChatGPT…), a turn's chain goes with the plans its
32
32
  * person has connected now (each `connectedPlans` source says), in one
33
33
  * order for everyone (theirs: a maker's own plan before Cursor;
34
- * `modelChoice.harnesses` lists them), and each model runs on those that
35
- * serve it before any API, so a subscription pays for every model it runs,
36
- * before credits: by the models a plan said it runs, where it said
37
- * (`served`). A tier names models; an entry naming a plan (`claude-plan/…`)
38
- * stands for its model on plans only. `plansFor` (shared/plans.ts) is what
39
- * a turn goes with, and `models.check` what a chain would try.
34
+ * `modelChoice.harnesses` lists them), by the models a plan said it runs,
35
+ * where it said (`served`). The tier's models run in its order, each on
36
+ * their plans that run it, then on credits. An org that wants members'
37
+ * subscriptions used whenever possible says so (`tiers.plansFirst`): every
38
+ * model on their plans before any on credits, then the tier's `fallbacks`
39
+ * (one model per maker) on their plans only. A tier names models; an
40
+ * entry naming a plan (`claude-plan/…`) stands for its model on plans
41
+ * only. `plansFor` (shared/plans.ts) is what a turn goes with, and
42
+ * `models.check` what a chain would try.
40
43
  *
41
44
  * Its queries (`modelChoice.offered`, `modelChoice.agent`) show the tiers
42
45
  * with what a typical message comes to at the org's prices (the app's
@@ -63,6 +66,8 @@
63
66
  * north: [{ model: "anthropic/claude-opus-5-5", effort: "medium" }, "openai/gpt-6.1-sol"],
64
67
  * east: { model: "anthropic/claude-sonnet-5-5", effort: "high" },
65
68
  * },
69
+ * // On members' plans only, where the org uses them whenever possible.
70
+ * fallbacks: ["anthropic/claude-opus-5-5", "openai/gpt-6.2-sol"],
66
71
  * },
67
72
  * },
68
73
  * },
@@ -70,7 +75,7 @@
70
75
  * ```
71
76
  */
72
77
  import { definePlugin } from "pairz";
73
- import { capAction, chooseAction, kindAction, orderAction, removeAction, restoreAction, saveAction, } from "./actions/choose.js";
78
+ import { capAction, checkFallback, chooseAction, kindAction, orderAction, plansFirstAction, removeAction, restoreAction, saveAction, } from "./actions/choose.js";
74
79
  import { modelAction } from "./actions/model.js";
75
80
  import { modelChoice } from "./collections/choice.js";
76
81
  import { tierKind, tierTemplate } from "./collections/template.js";
@@ -85,6 +90,7 @@ export const tiers = definePlugin({
85
90
  "tiers.model": modelAction,
86
91
  "tiers.choose": chooseAction,
87
92
  "tiers.cap": capAction,
93
+ "tiers.plansFirst": plansFirstAction,
88
94
  "tiers.save": saveAction,
89
95
  "tiers.order": orderAction,
90
96
  "tiers.remove": removeAction,
@@ -95,7 +101,7 @@ export const tiers = definePlugin({
95
101
  // Chat asks it which model chain each agent thinks with.
96
102
  agentModel: { tiers: { action: "tiers.model" } },
97
103
  },
98
- // Every tier has a title, and models that can be called as configured.
104
+ // Every tier has a title, models that can be called as configured, and fallbacks a plan runs.
99
105
  async check(merged) {
100
106
  for (const [name, tier] of Object.entries(appTiersOf(merged))) {
101
107
  if (!tier.title)
@@ -108,6 +114,11 @@ export const tiers = definePlugin({
108
114
  throw new Error(`Tier "${name}", ${kind}: ${error.message}`);
109
115
  }
110
116
  }
117
+ for (const fallback of tier.fallbacks ?? []) {
118
+ await checkFallback(merged, fallback).catch((error) => {
119
+ throw new Error(`Tier "${name}", fallbacks: ${error.message}`);
120
+ });
121
+ }
111
122
  }
112
123
  },
113
124
  });
@@ -52,10 +52,12 @@ export declare function plansOf(ctx: {
52
52
  */
53
53
  export declare function plansFor(ctx: Pick<ReadContext, "resources" | "call" | "actor">): Promise<Plans>;
54
54
  /**
55
- * The app's plans, as Your AI lists them: those that run a model some tier
56
- * of the org names (each chain, as it would be tried on every plan, by the
57
- * lists of those they've connected that said one), and those the person has
58
- * connected, even running none; in the plans' order, each with whether
59
- * they've connected it now, and the first model it runs.
55
+ * The app's plans, as Your AI lists them: every one, since any model can go
56
+ * in a tier (connecting Grok's plan is what makes Grok free in the picker);
57
+ * in the plans' order, each with whether they've connected it now, and the
58
+ * first model, in tier order, it runs (each chain, as it would be tried on
59
+ * every plan, by the lists of those they've connected that said one): what
60
+ * its test tries. One that runs none of the tiers' models is tested on the
61
+ * first its list has, or not at all.
60
62
  */
61
63
  export declare function harnessesShown(ctx: ReadContext): Promise<HarnessShown[]>;
@@ -34,11 +34,13 @@ export async function plansFor(ctx) {
34
34
  return plansOf(ctx, await connectedOf(ctx));
35
35
  }
36
36
  /**
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.
37
+ * The app's plans, as Your AI lists them: every one, since any model can go
38
+ * in a tier (connecting Grok's plan is what makes Grok free in the picker);
39
+ * in the plans' order, each with whether they've connected it now, and the
40
+ * first model, in tier order, it runs (each chain, as it would be tried on
41
+ * every plan, by the lists of those they've connected that said one): what
42
+ * its test tries. One that runs none of the tiers' models is tested on the
43
+ * first its list has, or not at all.
42
44
  */
43
45
  export async function harnessesShown(ctx) {
44
46
  const plans = harnessesOf(ctx);
@@ -60,7 +62,7 @@ export async function harnessesShown(ctx) {
60
62
  if (!first.has(provider))
61
63
  first.set(provider, id);
62
64
  }
63
- return all.filter((name) => first.has(name) || connected.has(name)).map((name) => {
65
+ return all.map((name) => {
64
66
  const listed = connected.get(name)?.[0];
65
67
  const model = first.get(name) ?? (listed ? `${name}/${listed}` : undefined);
66
68
  return {
@@ -15,8 +15,8 @@
15
15
  *
16
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
- * as their turns would run it: at the
19
- * first model it would try for them (`models.check`, plans first), one of
18
+ * as their turns would run it: at the first model it would try for them
19
+ * (`models.check`, as the org has members' plans used: `onPlans`), one of
20
20
  * their plans costing them nothing (`plan`), and a tier's price for them
21
21
  * (`yours`) beside the app's (`price`, which pages choosing for others show).
22
22
  */
@@ -101,6 +101,12 @@ export type TierShown = {
101
101
  kind: string;
102
102
  model: ModelShown;
103
103
  }[];
104
+ /** Its fallbacks on members' plans, in order: where the org uses them whenever possible. */
105
+ fallbacks?: {
106
+ id: string;
107
+ name: string;
108
+ effort?: string;
109
+ }[];
104
110
  };
105
111
  /** A kind of work: its title, and the app's agents that do it. */
106
112
  export type KindShown = {
@@ -125,11 +131,16 @@ export type Shown = {
125
131
  }[];
126
132
  /** The tier the org's plan gives, when the app has plans that say. */
127
133
  plan: string | null;
128
- /** The org's default, and what its members may use: up to `cap`, or only the default (`fixed`). */
134
+ /**
135
+ * The org's default, and what its members may use: up to `cap`, or only the
136
+ * default (`fixed`); where the app has plans, whether members'
137
+ * subscriptions are used whenever possible (`plansFirst`).
138
+ */
129
139
  org: {
130
140
  tier: string | null;
131
141
  cap: string | null;
132
142
  fixed: boolean;
143
+ plansFirst?: boolean;
133
144
  };
134
145
  space?: {
135
146
  tier: string | null;
@@ -1,7 +1,7 @@
1
1
  import { agentsOf } from "pairz/plugins/agents/contract";
2
2
  import { personOf } from "pairz";
3
- import { plansFor } from "./plans.js";
4
- import { entryOf, kindOf, kindsIn, ORG_CHOICE, personChoice, primaryOf, spaceChoice, threadChoice, tierIn, tiersIn, } from "./tiers.js";
3
+ import { harnessesOf, plansFor } from "./plans.js";
4
+ import { entryOf, kindOf, kindsIn, onPlans, ORG_CHOICE, personChoice, primaryOf, spaceChoice, threadChoice, tierIn, tiersIn, } from "./tiers.js";
5
5
  /** A typical reply's tokens, where the app measured no message (see above). */
6
6
  export const REPLY = { input: 20_000, cached: 16_000, output: 1_000 };
7
7
  /** The org's tiers and kinds, as it keeps them. */
@@ -47,6 +47,13 @@ const entriesOf = (ctx, ref) => (Array.isArray(ref) ? ref : [ref]).flatMap((entr
47
47
  const found = primaryOf(ctx, entry);
48
48
  return found ? [found] : [];
49
49
  });
50
+ /** What the models plugin offers of each model (its name, whether an org's key pays), each asked once. */
51
+ async function offeredOf(ctx, ids) {
52
+ const unique = [...new Set(ids)];
53
+ const offered = await Promise.all(unique.map((model) => ctx.call("models.offered", { model })
54
+ .then((answer) => answer.model, () => null)));
55
+ return new Map(unique.map((id, i) => [id, offered[i]]));
56
+ }
50
57
  /**
51
58
  * For each use, the plan of the person's (`theirs`) its chain would run on
52
59
  * first, as their turns try it (`models.check`), when it's a plan; each
@@ -54,17 +61,18 @@ const entriesOf = (ctx, ref) => (Array.isArray(ref) ? ref : [ref]).flatMap((entr
54
61
  */
55
62
  async function planFirsts(ctx, uses, theirs) {
56
63
  const asked = new Map();
57
- const firstOf = (ref) => {
58
- const key = JSON.stringify(ref);
64
+ const firstOf = (use) => {
65
+ const model = { model: use.ref, ...theirs, ...use.plans };
66
+ const key = JSON.stringify(model);
59
67
  let found = asked.get(key);
60
68
  if (!found) {
61
- found = ctx.call("models.check", { model: { model: ref, ...theirs }, port: "llm" })
69
+ found = ctx.call("models.check", { model, port: "llm" })
62
70
  .then((tried) => tried[0], () => undefined);
63
71
  asked.set(key, found);
64
72
  }
65
73
  return found;
66
74
  };
67
- const firsts = await Promise.all(uses.map((use) => firstOf(use.ref)));
75
+ const firsts = await Promise.all(uses.map(firstOf));
68
76
  return firsts.map((id) => id && theirs.harnesses.includes(id.slice(0, id.indexOf("/"))) ? id : undefined);
69
77
  }
70
78
  /**
@@ -80,10 +88,7 @@ async function modelsShown(ctx, uses, theirs = { harnesses: [] }) {
80
88
  const typical = typicalOf(ctx);
81
89
  const lists = uses.map((use) => entriesOf(ctx, use.ref));
82
90
  const firsts = theirs.harnesses.length ? planFirsts(ctx, uses, theirs) : undefined;
83
- const ids = [...new Set(lists.flat().map((entry) => entry.id))];
84
- const offered = await Promise.all(ids.map((model) => ctx.call("models.offered", { model })
85
- .then((answer) => answer.model, () => null)));
86
- const known = new Map(ids.map((id, i) => [id, offered[i]]));
91
+ const known = await offeredOf(ctx, lists.flat().map((entry) => entry.id));
87
92
  const declared = (ctx.resources.provider ?? {});
88
93
  // What one call is charged: each agent's (a plain reply's, without a measured message).
89
94
  const callOf = (agent) => {
@@ -177,11 +182,18 @@ export async function shownAt(ctx, where = {}) {
177
182
  // Every tier's chain for every kind, asked for at once, and taken back in the same order.
178
183
  const uses = list.flatMap(([, tier]) => kindNames.flatMap((kind) => {
179
184
  const ref = entryOf(tier, kind, kinds);
180
- return ref === undefined ? [] : [{ ref, agent: kinds[kind].base ?? kind }];
185
+ return ref === undefined
186
+ ? []
187
+ : [{ ref, agent: kinds[kind].base ?? kind, plans: onPlans(levels.org, tier) }];
181
188
  }));
182
189
  // The person's plans they can run now: what their turns go with.
183
190
  const theirs = person ? await plansFor(ctx) : { harnesses: [] };
184
- const shown = await modelsShown(ctx, uses, theirs);
191
+ // Each tier's fallbacks on members' plans, by name.
192
+ const fallbacks = Object.fromEntries(list.map(([name, tier]) => [name, entriesOf(ctx, tier.fallbacks ?? [])]));
193
+ const [shown, named] = await Promise.all([
194
+ modelsShown(ctx, uses, theirs),
195
+ offeredOf(ctx, Object.values(fallbacks).flat().map((entry) => entry.id)),
196
+ ]);
185
197
  let cursor = 0;
186
198
  const tiersShown = list.map(([name, tier]) => {
187
199
  const own = kindNames.flatMap((kind) => entryOf(tier, kind, kinds) === undefined ? [] : [{ kind, model: shown[cursor++] }]).filter((k) => !!k.model);
@@ -200,6 +212,15 @@ export async function shownAt(ctx, where = {}) {
200
212
  ...(tier.changed ? { changed: true } : {}),
201
213
  ...(tier.made ? { made: true } : {}),
202
214
  kinds: own,
215
+ ...(tier.fallbacks
216
+ ? {
217
+ fallbacks: fallbacks[name].map((entry) => ({
218
+ id: entry.id,
219
+ name: named.get(entry.id)?.name ?? entry.id.slice(entry.id.indexOf("/") + 1),
220
+ ...(entry.effort ? { effort: entry.effort } : {}),
221
+ })),
222
+ }
223
+ : {}),
203
224
  };
204
225
  });
205
226
  const offered = (name) => name && tiers[name] ? name : null;
@@ -227,6 +248,9 @@ export async function shownAt(ctx, where = {}) {
227
248
  tier: offered(levels.org?.tier),
228
249
  cap: offered(levels.org?.cap),
229
250
  fixed: levels.org?.fixed === true,
251
+ ...(Object.keys(harnessesOf(ctx)).length
252
+ ? { plansFirst: levels.org?.plansFirst === true }
253
+ : {}),
230
254
  },
231
255
  ...(where.space ? { space: { tier: offered(levels.space?.tier) } } : {}),
232
256
  ...(where.thread ? { thread: { tier: offered(levels.thread?.tier) } } : {}),
@@ -20,6 +20,11 @@
20
20
  * its default alone (`fixed`).
21
21
  * - **In order:** the app's tiers by their `order`, an org's own order over
22
22
  * it (`tiers.order`); a cap is "up to" a tier in that order.
23
+ * - **On members' plans:** a turn runs each model of its chain on the
24
+ * person's plans that run it, then on credits, model by model; where the
25
+ * org uses their subscriptions whenever possible (`plansFirst`), every
26
+ * model on their plans before any credits, then the tier's `fallbacks` on
27
+ * their plans only (`onPlans`).
23
28
  */
24
29
  import type { Resources } from "pairz";
25
30
  import type { ModelRef } from "pairz/plugins/models/contract";
@@ -32,6 +37,13 @@ export type Tier = {
32
37
  order?: number;
33
38
  /** Each kind of work's chain, by kind, as an agent's `model` takes it. */
34
39
  agents: Record<string, ModelRef>;
40
+ /**
41
+ * Where the org uses members' subscriptions whenever possible: models
42
+ * tried after any agent's chain, on the member's plans only, never on
43
+ * credits; one per maker (`["anthropic/claude-opus-5-5",
44
+ * "openai/gpt-6.2-sol", …]`), each as a chain's entry (settings allowed).
45
+ */
46
+ fallbacks?: ModelRef[];
35
47
  };
36
48
  /** A tier as the org has it: the app's (as it is, or `changed`), or one the org `made`. */
37
49
  export type OrgTier = Tier & {
@@ -46,6 +58,8 @@ export type Template = {
46
58
  description?: string;
47
59
  order?: number;
48
60
  agents?: Record<string, ModelRef>;
61
+ /** Its fallbacks on members' plans, over the app's. */
62
+ fallbacks?: ModelRef[];
49
63
  /** One of the app's the org took away. */
50
64
  off?: boolean;
51
65
  /** One the org made. */
@@ -68,12 +82,14 @@ export type OrgKind = {
68
82
  };
69
83
  /**
70
84
  * 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`).
85
+ * may use: tiers up to one (`cap`), or only its default (`fixed`); and
86
+ * whether their subscriptions are used whenever possible (`plansFirst`).
72
87
  */
73
88
  export type Choice = {
74
89
  tier?: string;
75
90
  cap?: string;
76
91
  fixed?: boolean;
92
+ plansFirst?: boolean;
77
93
  };
78
94
  /** Where a choice is kept. */
79
95
  export declare const ORG_CHOICE = "org";
@@ -125,6 +141,16 @@ export declare function tierIn(tiers: Record<string, unknown>, levels: Levels):
125
141
  tier: string;
126
142
  by: By;
127
143
  } | undefined;
144
+ /**
145
+ * How a tier's chains go with a member's plans, as the org says: where it
146
+ * uses their subscriptions whenever possible, every model on their plans
147
+ * first, then the tier's fallbacks on their plans only (the models plugin's
148
+ * `plansFirst` and `planFallbacks`); else nothing, model by model.
149
+ */
150
+ export declare function onPlans(org: Choice | null | undefined, tier: Tier | undefined): {
151
+ plansFirst?: true;
152
+ planFallbacks?: ModelRef[];
153
+ };
128
154
  /** Whether a tier is above the highest the org lets its members use (`cap`). */
129
155
  export declare function aboveCap(tiers: Record<string, unknown>, tier: string, cap?: string): boolean;
130
156
  /** A model, as a list: what's tried in order. */
@@ -57,7 +57,8 @@ export function tiersIn(ctx, templates) {
57
57
  if (mine?.off)
58
58
  continue;
59
59
  const changed = !!mine && (Object.keys(mine.agents ?? {}).length > 0 ||
60
- mine.title !== undefined || mine.description !== undefined);
60
+ mine.title !== undefined || mine.description !== undefined || !!mine.fallbacks);
61
+ const fallbacks = mine?.fallbacks ?? tier.fallbacks;
61
62
  out.push([name, {
62
63
  ...tier,
63
64
  // The org's place for it, over the app's.
@@ -65,6 +66,7 @@ export function tiersIn(ctx, templates) {
65
66
  ...(mine?.title ? { title: mine.title } : {}),
66
67
  ...(mine?.description !== undefined ? { description: mine.description } : {}),
67
68
  agents: { ...tier.agents, ...mine?.agents },
69
+ ...(fallbacks ? { fallbacks } : {}),
68
70
  app: true,
69
71
  ...(changed ? { changed: true } : {}),
70
72
  }]);
@@ -77,6 +79,7 @@ export function tiersIn(ctx, templates) {
77
79
  ...(mine.description ? { description: mine.description } : {}),
78
80
  order: mine.order ?? 1000,
79
81
  agents: { ...mine.agents },
82
+ ...(mine.fallbacks ? { fallbacks: mine.fallbacks } : {}),
80
83
  made: true,
81
84
  }]);
82
85
  }
@@ -110,6 +113,20 @@ export function tierIn(tiers, levels) {
110
113
  const plan = offered(tiers, levels.plan) ?? Object.keys(tiers)[0];
111
114
  return plan ? { tier: plan, by: "plan" } : undefined;
112
115
  }
116
+ /**
117
+ * How a tier's chains go with a member's plans, as the org says: where it
118
+ * uses their subscriptions whenever possible, every model on their plans
119
+ * first, then the tier's fallbacks on their plans only (the models plugin's
120
+ * `plansFirst` and `planFallbacks`); else nothing, model by model.
121
+ */
122
+ export function onPlans(org, tier) {
123
+ if (!org?.plansFirst)
124
+ return {};
125
+ return {
126
+ plansFirst: true,
127
+ ...(tier?.fallbacks?.length ? { planFallbacks: tier.fallbacks } : {}),
128
+ };
129
+ }
113
130
  /** Whether a tier is above the highest the org lets its members use (`cap`). */
114
131
  export function aboveCap(tiers, tier, cap) {
115
132
  if (!cap || !Object.hasOwn(tiers, cap) || !Object.hasOwn(tiers, tier))
@@ -12,8 +12,11 @@
12
12
  * the org can run, each saying how it's paid for), duplicate one into a
13
13
  * new tier, make one from nothing, move one before or after another, take
14
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
+ * tiers, up to one, or only the default). Where the app has plans, they
16
+ * say whether members' subscriptions are used whenever possible (off: the
17
+ * tier's order, model by model), and each tier's fallbacks on members'
18
+ * subscriptions. On a plan of credits given once, a heavier default says
19
+ * how much faster it spends them.
17
20
  * - **The team** (team.tsx): the agents every space starts with.
18
21
  *
19
22
  * Anyone else reads it, and is told who changes it. Everything shown is a
@@ -25,6 +28,12 @@ import type { ModelShown, Shown, TierShown } from "../../contract.js";
25
28
  import { type TeamAgent } from "./team.js";
26
29
  type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
27
30
  export declare const tiersOrgView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
31
+ /** A tier being customized (`name`), or a new one, maybe copied from another. */
32
+ type Editing = {
33
+ name?: string;
34
+ from?: string;
35
+ title?: string;
36
+ };
28
37
  export declare function OrgAgents({ shown, team, may, org, personal, call }: {
29
38
  shown: Shown;
30
39
  team?: TeamAgent[];
@@ -62,6 +71,24 @@ export declare function TierCard({ tier, shown, current, may, busy, onChoose, on
62
71
  onRemove(): void;
63
72
  onRestore(): void;
64
73
  }): ReactNode;
74
+ /**
75
+ * Customizing a tier, or making one (a dialog): its name and what it's for,
76
+ * then each kind of work, with the agents that do it, its model and what it
77
+ * falls back to (team's picker, `model.pick`, offering every model the org
78
+ * can run, each saying how it's paid for: `members`, for an org of others,
79
+ * that those without a model's plan fall back to the next), and adding a
80
+ * kind of work of the org's own; where the app has plans, the tier's
81
+ * fallbacks on members' subscriptions. Saved at once (`tiers.save`): only
82
+ * what changed.
83
+ */
84
+ export declare function TierEditor({ shown, team, editing, members, call, onClose }: {
85
+ shown: Shown;
86
+ team?: TeamAgent[];
87
+ editing: Editing;
88
+ members: boolean;
89
+ call: Call;
90
+ onClose(): void;
91
+ }): ReactNode;
65
92
  /** What a model falls back to, each name once: "GPT-6 Luna, Claude Haiku 5.5". */
66
93
  export declare function thenSaid(model: ModelShown): string | undefined;
67
94
  /** A model as a short line: "Claude Haiku 5.5, low effort, then GPT-6 Luna". */