@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
package/tiers/mod.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Tiers: how hard an app's agents think, chosen by budget rather than model
3
+ * by model. Agents don't hold models here: each does a **kind of work**, and
4
+ * a **tier** is a template giving each kind a model chain (a model, its
5
+ * effort, and what's tried after it when it fails). Every conversation runs
6
+ * on a tier.
7
+ *
8
+ * - **The app** declares its tiers (`tiers`: each a title, what it's good
9
+ * for, an order, and a chain for each kind, as an agent's `model` takes
10
+ * one) and names its kinds (`tierKinds`: `{ north: { title: "Decides" } }`;
11
+ * the kinds are the tiers' keys, and an app agent of that name does that
12
+ * kind). Any other agent says which kind it does (`like`), else it does the
13
+ * app's first.
14
+ * - **An org** keeps its own version of each tier (kinds' chains changed, a
15
+ * title), takes tiers away, makes new ones (`tiers.save`, `tiers.remove`,
16
+ * `tiers.restore`; `tierTemplate`), and adds kinds of work of its own, each
17
+ * based on one of the app's (`tiers.kind`; `tierKind`). Its owners and
18
+ * admins do; everyone in it reads them.
19
+ * - **Which tier, first that applies:** the conversation's, the person's own
20
+ * default for new chats, the space's, the org's, then the tier the org's
21
+ * plan gives (the `planTier` resource, which credits fills)
22
+ * (`tiers.choose`; `modelChoice`, by name, never copies). The org can cap
23
+ * what its members choose (`tiers.cap`); its owners and admins aren't
24
+ * bound by it, and its budget bounds what anyone spends.
25
+ * - **Every turn:** chat asks `tiers.model` through its `agentModel` resource,
26
+ * for every agent, with the kind it works like. A change applies from each
27
+ * conversation's next reply.
28
+ * - **Plans first:** where the app has people's plans (providers with
29
+ * `harness`: Claude Code, ChatGPT…), a turn's chain goes with the plans its
30
+ * person has connected now (each `connectedPlans` source says), in their
31
+ * order (`tiers.harnesses`; `modelChoice.harnesses` lists them), and each
32
+ * model runs on those that serve it before any API: by the models a plan
33
+ * said it runs, where it said (`served`). A tier names models;
34
+ * an entry naming a plan (`claude-plan/…`) stands for its model on plans
35
+ * only. `plansFor` (shared/plans.ts) is what a turn goes with, and
36
+ * `models.check` what a chain would try.
37
+ *
38
+ * Its queries (`modelChoice.offered`, `modelChoice.agent`) show the tiers
39
+ * with what a typical message comes to at the org's prices (the app's
40
+ * `typicalMessage`, measured, else a plain reply), and how far the plan's
41
+ * credits go (`planCredits`).
42
+ *
43
+ * ```ts
44
+ * plugins: [models, chat, ...access, tiers, definePlugin({
45
+ * name: "app",
46
+ * resources: {
47
+ * tierKinds: { north: { title: "Decides" }, east: { title: "Builds" } },
48
+ * tiers: {
49
+ * everyday: {
50
+ * title: "Everyday",
51
+ * description: "Quick answers, routine work, volume",
52
+ * order: 1,
53
+ * agents: { north: "anthropic/claude-haiku-5-5", east: "openai/gpt-6-luna" },
54
+ * },
55
+ * expert: {
56
+ * title: "Expert",
57
+ * description: "Hard problems, decisions that matter",
58
+ * order: 3,
59
+ * agents: {
60
+ * north: [{ model: "anthropic/claude-opus-5-5", effort: "medium" }, "openai/gpt-6.1-sol"],
61
+ * east: { model: "anthropic/claude-sonnet-5-5", effort: "high" },
62
+ * },
63
+ * },
64
+ * },
65
+ * },
66
+ * })]
67
+ * ```
68
+ */
69
+ import { type Plugin } from "pairz";
70
+ export * from "./contract.js";
71
+ export declare const tiers: Plugin;
72
+ export default tiers;
package/tiers/mod.js ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Tiers: how hard an app's agents think, chosen by budget rather than model
3
+ * by model. Agents don't hold models here: each does a **kind of work**, and
4
+ * a **tier** is a template giving each kind a model chain (a model, its
5
+ * effort, and what's tried after it when it fails). Every conversation runs
6
+ * on a tier.
7
+ *
8
+ * - **The app** declares its tiers (`tiers`: each a title, what it's good
9
+ * for, an order, and a chain for each kind, as an agent's `model` takes
10
+ * one) and names its kinds (`tierKinds`: `{ north: { title: "Decides" } }`;
11
+ * the kinds are the tiers' keys, and an app agent of that name does that
12
+ * kind). Any other agent says which kind it does (`like`), else it does the
13
+ * app's first.
14
+ * - **An org** keeps its own version of each tier (kinds' chains changed, a
15
+ * title), takes tiers away, makes new ones (`tiers.save`, `tiers.remove`,
16
+ * `tiers.restore`; `tierTemplate`), and adds kinds of work of its own, each
17
+ * based on one of the app's (`tiers.kind`; `tierKind`). Its owners and
18
+ * admins do; everyone in it reads them.
19
+ * - **Which tier, first that applies:** the conversation's, the person's own
20
+ * default for new chats, the space's, the org's, then the tier the org's
21
+ * plan gives (the `planTier` resource, which credits fills)
22
+ * (`tiers.choose`; `modelChoice`, by name, never copies). The org can cap
23
+ * what its members choose (`tiers.cap`); its owners and admins aren't
24
+ * bound by it, and its budget bounds what anyone spends.
25
+ * - **Every turn:** chat asks `tiers.model` through its `agentModel` resource,
26
+ * for every agent, with the kind it works like. A change applies from each
27
+ * conversation's next reply.
28
+ * - **Plans first:** where the app has people's plans (providers with
29
+ * `harness`: Claude Code, ChatGPT…), a turn's chain goes with the plans its
30
+ * person has connected now (each `connectedPlans` source says), in their
31
+ * order (`tiers.harnesses`; `modelChoice.harnesses` lists them), and each
32
+ * model runs on those that serve it before any API: by the models a plan
33
+ * said it runs, where it said (`served`). A tier names models;
34
+ * an entry naming a plan (`claude-plan/…`) stands for its model on plans
35
+ * only. `plansFor` (shared/plans.ts) is what a turn goes with, and
36
+ * `models.check` what a chain would try.
37
+ *
38
+ * Its queries (`modelChoice.offered`, `modelChoice.agent`) show the tiers
39
+ * with what a typical message comes to at the org's prices (the app's
40
+ * `typicalMessage`, measured, else a plain reply), and how far the plan's
41
+ * credits go (`planCredits`).
42
+ *
43
+ * ```ts
44
+ * plugins: [models, chat, ...access, tiers, definePlugin({
45
+ * name: "app",
46
+ * resources: {
47
+ * tierKinds: { north: { title: "Decides" }, east: { title: "Builds" } },
48
+ * tiers: {
49
+ * everyday: {
50
+ * title: "Everyday",
51
+ * description: "Quick answers, routine work, volume",
52
+ * order: 1,
53
+ * agents: { north: "anthropic/claude-haiku-5-5", east: "openai/gpt-6-luna" },
54
+ * },
55
+ * expert: {
56
+ * title: "Expert",
57
+ * description: "Hard problems, decisions that matter",
58
+ * order: 3,
59
+ * agents: {
60
+ * north: [{ model: "anthropic/claude-opus-5-5", effort: "medium" }, "openai/gpt-6.1-sol"],
61
+ * east: { model: "anthropic/claude-sonnet-5-5", effort: "high" },
62
+ * },
63
+ * },
64
+ * },
65
+ * },
66
+ * })]
67
+ * ```
68
+ */
69
+ import { definePlugin } from "pairz";
70
+ import { capAction, chooseAction, harnessesAction, kindAction, removeAction, restoreAction, saveAction, } from "./actions/choose.js";
71
+ import { modelAction } from "./actions/model.js";
72
+ import { modelChoice } from "./collections/choice.js";
73
+ import { tierKind, tierTemplate } from "./collections/template.js";
74
+ import { appTiersOf } from "./shared/tiers.js";
75
+ export * from "./contract.js";
76
+ export const tiers = definePlugin({
77
+ name: "tiers",
78
+ // Its choices are an org's, its spaces' and its conversations', changed by who runs them.
79
+ requires: ["chat", "spaces"],
80
+ collections: { modelChoice, tierTemplate, tierKind },
81
+ actions: {
82
+ "tiers.model": modelAction,
83
+ "tiers.choose": chooseAction,
84
+ "tiers.cap": capAction,
85
+ "tiers.save": saveAction,
86
+ "tiers.remove": removeAction,
87
+ "tiers.restore": restoreAction,
88
+ "tiers.kind": kindAction,
89
+ "tiers.harnesses": harnessesAction,
90
+ },
91
+ resources: {
92
+ // Chat asks it which model chain each agent thinks with.
93
+ agentModel: { tiers: { action: "tiers.model" } },
94
+ },
95
+ // Every tier has a title, and models that can be called as configured.
96
+ async check(merged) {
97
+ for (const [name, tier] of Object.entries(appTiersOf(merged))) {
98
+ if (!tier.title)
99
+ throw new Error(`Tier "${name}" has no title`);
100
+ for (const [kind, model] of Object.entries(tier.agents ?? {})) {
101
+ try {
102
+ await merged.call("models.check", { model, port: "llm" });
103
+ }
104
+ catch (error) {
105
+ throw new Error(`Tier "${name}", ${kind}: ${error.message}`);
106
+ }
107
+ }
108
+ }
109
+ },
110
+ });
111
+ export default tiers;
@@ -0,0 +1,65 @@
1
+ /**
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.
10
+ */
11
+ import { type ReadContext, type Resources } from "pairz";
12
+ import type { Provider } from "pairz/plugins/models/contract";
13
+ /** One of the app's plans, as a person orders them. */
14
+ export type HarnessShown = {
15
+ /** Its provider: `claude-plan`. */
16
+ name: string;
17
+ /** What people call it: "Claude plan". */
18
+ title: string;
19
+ /** The plan it runs on ("ChatGPT"): two ways to run one plan show as one. */
20
+ plan: string;
21
+ /** The person has it now: their account, or signed in on a computer of theirs. */
22
+ connected: boolean;
23
+ /** The first model, in tier order, it runs (`claude-plan/claude-haiku-5-5`): what a test tries. */
24
+ model: string;
25
+ };
26
+ /** The app's plans, by provider name. */
27
+ export declare function harnessesOf(ctx: {
28
+ resources: Resources;
29
+ }): Record<string, Provider>;
30
+ /** The app's plans in a person's order: theirs first (`mine`), then the rest, lowest `order` first. */
31
+ export declare function orderOf(ctx: {
32
+ resources: Resources;
33
+ }, mine?: string[]): string[];
34
+ /**
35
+ * A person's plans, as a model list goes with them (`{ model, ...plans }`):
36
+ * those they can run now, in their order, and the models those that said so
37
+ * run (`served`, by plan), when any did.
38
+ */
39
+ export type Plans = {
40
+ harnesses: string[];
41
+ served?: Record<string, string[]>;
42
+ };
43
+ /**
44
+ * The plans the person a call is for has connected now, as each source says
45
+ * (as them), each with the models it said it runs, when it said.
46
+ */
47
+ export declare function connectedOf(ctx: Pick<ReadContext, "resources" | "call">): Promise<Map<string, string[] | undefined>>;
48
+ /** Of `connected` (connectedOf's), the person's plans in their order (`mine`), with their lists. */
49
+ export declare function plansOf(ctx: {
50
+ resources: Resources;
51
+ }, connected: Map<string, string[] | undefined>, mine?: string[]): Plans;
52
+ /**
53
+ * The plans the person a call is for can run now, in their order (`mine`:
54
+ * their `harnesses`), with the models those that said so run: what a model
55
+ * list goes with (`{ model, ...plans }`).
56
+ */
57
+ export declare function plansFor(ctx: Pick<ReadContext, "resources" | "call" | "actor">, mine?: string[]): Promise<Plans>;
58
+ /**
59
+ * The app's plans, as a person orders them: those that run a model some
60
+ * tier of the org names (each chain, as it would be tried on every plan, by
61
+ * the lists of those they've connected that said one), in their order, each
62
+ * with whether they've connected it now, and the first model, in tier order,
63
+ * it runs.
64
+ */
65
+ export declare function harnessesShown(ctx: ReadContext): Promise<HarnessShown[]>;
@@ -0,0 +1,91 @@
1
+ /**
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.
10
+ */
11
+ import { personOf } from "pairz";
12
+ import { orgTiersOf } from "./shown.js";
13
+ import { personChoice } from "./tiers.js";
14
+ /** The app's plans, by provider name. */
15
+ export function harnessesOf(ctx) {
16
+ const declared = (ctx.resources.provider ?? {});
17
+ return Object.fromEntries(Object.entries(declared).filter((entry) => !!entry[1]?.harness));
18
+ }
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));
38
+ const served = Object.fromEntries(harnesses.flatMap((name) => connected.get(name) ? [[name, connected.get(name)]] : []));
39
+ return { harnesses, ...(Object.keys(served).length ? { served } : {}) };
40
+ }
41
+ /**
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 }`).
45
+ */
46
+ export async function plansFor(ctx, mine) {
47
+ if (!personOf(ctx.actor) || !Object.keys(harnessesOf(ctx)).length)
48
+ return { harnesses: [] };
49
+ return plansOf(ctx, await connectedOf(ctx), mine);
50
+ }
51
+ /**
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.
57
+ */
58
+ export async function harnessesShown(ctx) {
59
+ const plans = harnessesOf(ctx);
60
+ const person = personOf(ctx.actor);
61
+ if (!person || !Object.keys(plans).length)
62
+ 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));
71
+ // Every plan, those that said which models they run by their lists.
72
+ const { served } = plansOf(ctx, connected);
73
+ const tried = await Promise.all(chains.map((chain) => ctx.call("models.check", {
74
+ model: { model: chain, harnesses: all, ...(served ? { served } : {}) },
75
+ port: "llm",
76
+ }).catch(() => [])));
77
+ // Each plan a chain runs, with the first model it runs there.
78
+ const first = new Map();
79
+ for (const id of tried.flat()) {
80
+ const provider = id.slice(0, id.indexOf("/"));
81
+ if (!first.has(provider))
82
+ first.set(provider, id);
83
+ }
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
+ }));
91
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * What a page shows of tiers, read as the person looking: the org's tiers
3
+ * (the app's as the org keeps them, and those it made), each kind of work's
4
+ * model chain in them by name, and what a typical message comes to at this
5
+ * org's prices; the kinds of work and the app's agents of each; what the org,
6
+ * a space, a conversation and the person chose, and what applies; and what
7
+ * the org's plan gives in credits, so a page can say how far they go.
8
+ *
9
+ * A typical message is what the app measured one takes (its `typicalMessage`
10
+ * resource): each agent's calls per message, and each call's tokens, priced
11
+ * at the agent's model in each tier. A tier's price is the sum. Without one,
12
+ * a plain reply for comparing tiers: 20,000 tokens in, 16,000 of them read
13
+ * from the cache (a conversation's history mostly is), and 1,000 out, each
14
+ * agent's alike, and a tier's price is its agents' average.
15
+ *
16
+ * With the person's plans (`plansFor`: those they can run now, in their
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
20
+ * their plans costing them nothing (`plan`), and a tier's price for them
21
+ * (`yours`) beside the app's (`price`, which pages choosing for others show).
22
+ */
23
+ import type { ReadContext } from "pairz";
24
+ import { type By, type Kind, type Levels, type OrgTier, type Template } from "./tiers.js";
25
+ /** A typical reply's tokens, where the app measured no message (see above). */
26
+ export declare const REPLY: {
27
+ input: number;
28
+ cached: number;
29
+ output: number;
30
+ };
31
+ /**
32
+ * A `typicalMessage` resource: what one message of a person's takes of each of
33
+ * the app's agents, on average, measured from what they really did: how many
34
+ * calls (`calls`: 4.05 for the agent who answers, 0.6 for one asked now and
35
+ * then), and each call's tokens: `input` (with what's read from the cache),
36
+ * `cached`, `cacheWrite` and `output`. An agent it doesn't name isn't counted.
37
+ */
38
+ export type TypicalMessage = Record<string, {
39
+ calls: number;
40
+ input: number;
41
+ cached?: number;
42
+ cacheWrite?: number;
43
+ output: number;
44
+ }>;
45
+ /**
46
+ * A `planCredits` resource: the Action saying what credits the org's plan
47
+ * gives (credits' `billing.credits`), `{}` in, `PlanCredits` or null out.
48
+ */
49
+ export type PlanCredits = {
50
+ action: string;
51
+ };
52
+ /** What the org's plan gives in credits: once (a trial's), or each month, for the org or a seat. */
53
+ export type CreditsShown = {
54
+ /** The plan's name and title: `free`, "Free". */
55
+ plan: string;
56
+ title: string;
57
+ /** USD. */
58
+ amount: number;
59
+ every: "once" | "month";
60
+ perSeat?: true;
61
+ };
62
+ /** A model as a page shows it: its name, effort, a typical message's part, and what's tried after it. */
63
+ export type ModelShown = {
64
+ id: string;
65
+ name: string;
66
+ effort?: string;
67
+ /** USD, at this org's prices; null when nothing prices it. */
68
+ price: number | null;
69
+ /** It runs on the org's own key: its provider charges for it, not the app. */
70
+ ownKey?: true;
71
+ /** What's tried after it when it fails, in order. */
72
+ fallbacks?: {
73
+ id: string;
74
+ name: string;
75
+ effort?: string;
76
+ }[];
77
+ /**
78
+ * The plan of the person looking that answers it first, as their turns
79
+ * try it (`"h-chatgpt/gpt-6.2-sol"`): it costs them nothing. `price` stays
80
+ * what it costs on the app's models.
81
+ */
82
+ plan?: string;
83
+ };
84
+ export type TierShown = {
85
+ name: string;
86
+ title: string;
87
+ description?: string;
88
+ /** A typical message (its kinds' sum), or reply (their average), in USD; null when none is priced. */
89
+ price: number | null;
90
+ /**
91
+ * The same for the person looking, with their plans (0 when plans answer
92
+ * every kind): only when a plan of theirs answers some kind here.
93
+ */
94
+ yours?: number | null;
95
+ /** The app's (as it is, or `changed` by the org), or one the org `made`. */
96
+ app?: true;
97
+ changed?: true;
98
+ made?: true;
99
+ /** Each kind of work's chain here, in the kinds' order. */
100
+ kinds: {
101
+ kind: string;
102
+ model: ModelShown;
103
+ }[];
104
+ };
105
+ /** A kind of work: its title, and the app's agents that do it. */
106
+ export type KindShown = {
107
+ kind: string;
108
+ title: string;
109
+ description?: string;
110
+ /** For one the org added: the app's kind it starts from. */
111
+ base?: string;
112
+ agents: {
113
+ agent: string;
114
+ name: string;
115
+ icon?: string;
116
+ }[];
117
+ };
118
+ export type Shown = {
119
+ tiers: TierShown[];
120
+ kinds: KindShown[];
121
+ /** The app's tiers the org took away, to put back. */
122
+ removed: {
123
+ name: string;
124
+ title: string;
125
+ }[];
126
+ /** The tier the org's plan gives, when the app has plans that say. */
127
+ plan: string | null;
128
+ org: {
129
+ tier: string | null;
130
+ cap: string | null;
131
+ };
132
+ space?: {
133
+ tier: string | null;
134
+ };
135
+ thread?: {
136
+ tier: string | null;
137
+ };
138
+ /** The person's own default for new chats. */
139
+ person: {
140
+ tier: string | null;
141
+ };
142
+ /** What applies where it was asked: the tier in force and who chose it. */
143
+ now: {
144
+ tier: string;
145
+ by: By;
146
+ } | null;
147
+ /** What prices are for: a typical message the app measured, else a plain reply. */
148
+ per: "message" | "reply";
149
+ reply: typeof REPLY;
150
+ /** What the org's plan gives in credits, when the app has plans that say. */
151
+ credits: CreditsShown | null;
152
+ };
153
+ /** One agent where it works: its kind, the tier in force there, and its chain in it. */
154
+ export type AgentNow = {
155
+ kind: string;
156
+ kindTitle: string;
157
+ tier: string;
158
+ tierTitle: string;
159
+ by: By;
160
+ model: ModelShown;
161
+ };
162
+ /** The org's tiers and kinds, as it keeps them. */
163
+ export declare function orgTiersOf(ctx: ReadContext): Promise<{
164
+ tiers: Record<string, OrgTier>;
165
+ kinds: Record<string, Kind>;
166
+ templates: import("pairz").WithId<Template>[];
167
+ }>;
168
+ /** What each level chose, where asked: the conversation, the person, the space, the org, the plan. */
169
+ export declare function levelsOf(ctx: ReadContext, where: {
170
+ space?: string;
171
+ thread?: string;
172
+ person?: string;
173
+ }): Promise<Levels>;
174
+ /** Everything a page shows, at the org's level, or where asked (a space, a conversation). */
175
+ export declare function shownAt(ctx: ReadContext, where?: {
176
+ space?: string;
177
+ thread?: string;
178
+ }): Promise<Shown>;
179
+ /**
180
+ * One agent where it works (a space, maybe a conversation): its kind of work,
181
+ * the tier in force there and who chose it, and its chain in that tier; null
182
+ * when no tier applies.
183
+ */
184
+ export declare function agentAt(ctx: ReadContext, agent: string, where: {
185
+ space?: string;
186
+ thread?: string;
187
+ }): Promise<AgentNow | null>;