@copilotz/team 1.0.0-rc.53 → 1.0.0-rc.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WORDS.md +156 -0
- package/package.json +2 -2
- package/team/actions/agent.d.ts +10 -0
- package/team/actions/agent.js +226 -7
- package/team/actions/define.js +7 -3
- package/team/collections/agent.d.ts +52 -7
- package/team/collections/agent.js +56 -5
- package/team/mod.d.ts +7 -0
- package/team/mod.js +14 -1
- package/team/resources/propose.d.ts +1 -0
- package/team/resources/propose.js +97 -0
- package/team/shared/definition.d.ts +1 -1
- package/team/shared/definition.js +5 -4
- package/team/shared/everywhere.d.ts +11 -0
- package/team/shared/everywhere.js +29 -0
- package/team/views/web/agent-add.js +14 -4
- package/team/views/web/agent-describe.d.ts +38 -0
- package/team/views/web/agent-describe.js +44 -0
- package/team/views/web/agent-fields.d.ts +3 -1
- package/team/views/web/agent-fields.js +2 -2
- package/team/views/web/agent-known.js +2 -1
- package/team/views/web/agent-new.d.ts +4 -1
- package/team/views/web/agent-new.js +26 -5
- package/team/views/web/agent-org.d.ts +12 -0
- package/team/views/web/agent-org.js +89 -0
- package/team/views/web/agent.d.ts +7 -4
- package/team/views/web/agent.js +81 -28
- package/team/views/web/model-pick.d.ts +3 -1
- package/team/views/web/model-pick.js +4 -1
- package/team/views/web/style.d.ts +1 -1
- package/team/views/web/style.js +5 -0
- package/team/views/web/words.d.ts +1 -1
- package/team/views/web/words.js +28 -0
- package/team/web.js +2 -0
- package/tiers/actions/choose.d.ts +5 -1
- package/tiers/actions/choose.js +247 -66
- package/tiers/actions/model.js +31 -22
- package/tiers/collections/choice.d.ts +17 -10
- package/tiers/collections/choice.js +39 -27
- package/tiers/collections/template.d.ts +90 -0
- package/tiers/collections/template.js +41 -0
- package/tiers/contract.d.ts +10 -8
- package/tiers/mod.d.ts +30 -21
- package/tiers/mod.js +45 -36
- package/tiers/shared/shown.d.ts +131 -49
- package/tiers/shared/shown.js +192 -98
- package/tiers/shared/tiers.d.ts +105 -62
- package/tiers/shared/tiers.js +127 -86
- package/tiers/views/web/composer.d.ts +12 -0
- package/tiers/views/web/composer.js +79 -0
- package/tiers/views/web/org.d.ts +44 -21
- package/tiers/views/web/org.js +231 -84
- package/tiers/views/web/say.d.ts +138 -0
- package/tiers/views/web/say.js +142 -0
- package/tiers/views/web/setup.d.ts +23 -0
- package/tiers/views/web/setup.js +80 -0
- package/tiers/views/web/space.d.ts +8 -20
- package/tiers/views/web/space.js +30 -59
- package/tiers/views/web/style.d.ts +1 -1
- package/tiers/views/web/style.js +98 -4
- package/tiers/views/web/team.d.ts +38 -0
- package/tiers/views/web/team.js +118 -0
- package/tiers/views/web/words.d.ts +36 -16
- package/tiers/views/web/words.js +102 -35
- package/tiers/web.d.ts +18 -9
- package/tiers/web.js +36 -10
package/tiers/shared/shown.js
CHANGED
|
@@ -1,155 +1,249 @@
|
|
|
1
|
-
import { agentsOf
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { agentsOf } from "copilotz/plugins/agents/contract";
|
|
2
|
+
import { personOf } from "copilotz";
|
|
3
|
+
import { entryOf, kindOf, kindsIn, ORG_CHOICE, personChoice, primaryOf, spaceChoice, threadChoice, tierIn, tiersIn, } from "./tiers.js";
|
|
4
|
+
/** A typical reply's tokens, where the app measured no message (see above). */
|
|
4
5
|
export const REPLY = { input: 20_000, cached: 16_000, output: 1_000 };
|
|
6
|
+
/** The org's tiers and kinds, as it keeps them. */
|
|
7
|
+
export async function orgTiersOf(ctx) {
|
|
8
|
+
const [templates, kinds] = await Promise.all([
|
|
9
|
+
ctx.db.collection("tierTemplate").find({}),
|
|
10
|
+
ctx.db.collection("tierKind").find({}),
|
|
11
|
+
]);
|
|
12
|
+
return { tiers: tiersIn(ctx, templates), kinds: kindsIn(ctx, kinds), templates };
|
|
13
|
+
}
|
|
5
14
|
const choices = (ctx) => ctx.db.collection("modelChoice");
|
|
6
15
|
/** The org's plan's tier, through the `planTier` resource when something declares it. */
|
|
7
16
|
async function planTierOf(ctx) {
|
|
8
17
|
const source = ctx.resources.planTier;
|
|
9
18
|
return source?.action ? await ctx.call(source.action, {}) : null;
|
|
10
19
|
}
|
|
11
|
-
/** What
|
|
12
|
-
export async function levelsOf(ctx,
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
/** What each level chose, where asked: the conversation, the person, the space, the org, the plan. */
|
|
21
|
+
export async function levelsOf(ctx, where) {
|
|
22
|
+
const one = (id) => id ? choices(ctx).findOne({ _id: id }) : Promise.resolve(null);
|
|
23
|
+
const [thread, person, space, org, plan] = await Promise.all([
|
|
24
|
+
one(where.thread && threadChoice(where.thread)),
|
|
25
|
+
one(where.person && personChoice(where.person)),
|
|
26
|
+
one(where.space && spaceChoice(where.space)),
|
|
27
|
+
one(ORG_CHOICE),
|
|
16
28
|
planTierOf(ctx),
|
|
17
29
|
]);
|
|
18
|
-
return {
|
|
30
|
+
return { thread, person, space, org, plan };
|
|
31
|
+
}
|
|
32
|
+
/** The app's measured message, when it has one. */
|
|
33
|
+
const typicalOf = (ctx) => {
|
|
34
|
+
const typical = ctx.resources.typicalMessage;
|
|
35
|
+
return typical && Object.keys(typical).length ? typical : undefined;
|
|
36
|
+
};
|
|
37
|
+
/** What the org's plan gives in credits, through the `planCredits` resource when something declares it. */
|
|
38
|
+
async function creditsOf(ctx) {
|
|
39
|
+
const source = ctx.resources.planCredits;
|
|
40
|
+
if (!source?.action)
|
|
41
|
+
return null;
|
|
42
|
+
return await ctx.call(source.action, {}).catch(() => null);
|
|
19
43
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
44
|
+
/** Each model a ref tries, in order, each as `primaryOf` reads one. */
|
|
45
|
+
const entriesOf = (ctx, ref) => (Array.isArray(ref) ? ref : [ref]).flatMap((entry) => {
|
|
46
|
+
const found = primaryOf(ctx, entry);
|
|
47
|
+
return found ? [found] : [];
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Names and prices for models, by `"provider/model"` and effort, each asked
|
|
51
|
+
* once: a typical message's part for the agent (its calls, each call's
|
|
52
|
+
* tokens), else a plain reply. A model is named by the first it tries, and
|
|
53
|
+
* priced at the first the app charges something for: one on the org's own key
|
|
54
|
+
* or free here (a person's ChatGPT plan) is passed over for the next, as a
|
|
55
|
+
* turn is when the person hasn't connected that plan; a list all on the org's
|
|
56
|
+
* own keys isn't priced.
|
|
57
|
+
*/
|
|
58
|
+
async function modelsShown(ctx, uses) {
|
|
59
|
+
const typical = typicalOf(ctx);
|
|
60
|
+
const lists = uses.map((use) => entriesOf(ctx, use.ref));
|
|
61
|
+
const ids = [...new Set(lists.flat().map((entry) => entry.id))];
|
|
24
62
|
const offered = await Promise.all(ids.map((model) => ctx.call("models.offered", { model })
|
|
25
63
|
.then((answer) => answer.model, () => null)));
|
|
26
64
|
const known = new Map(ids.map((id, i) => [id, offered[i]]));
|
|
27
65
|
const declared = (ctx.resources.provider ?? {});
|
|
28
|
-
// What
|
|
29
|
-
const
|
|
30
|
-
|
|
66
|
+
// What one call is charged: each agent's (a plain reply's, without a measured message).
|
|
67
|
+
const callOf = (agent) => {
|
|
68
|
+
const measured = typical?.[agent];
|
|
69
|
+
if (!typical)
|
|
70
|
+
return REPLY;
|
|
71
|
+
if (!measured)
|
|
72
|
+
return undefined;
|
|
73
|
+
const { calls: _, ...tokens } = measured;
|
|
74
|
+
return tokens;
|
|
75
|
+
};
|
|
76
|
+
const keyOf = (id, agent) => typical ? `${id} ${agent}` : id;
|
|
77
|
+
// Every model each tries that's on the app's keys, when there's a ledger, each call asked once.
|
|
78
|
+
const charged = lists.map((list) => ctx.resources.usage ? list.filter((entry) => !known.get(entry.id)?.ownKey) : []);
|
|
79
|
+
const asked = new Map();
|
|
80
|
+
charged.forEach((list, i) => {
|
|
81
|
+
if (!callOf(uses[i].agent))
|
|
82
|
+
return;
|
|
83
|
+
for (const entry of list) {
|
|
84
|
+
asked.set(keyOf(entry.id, uses[i].agent), { id: entry.id, agent: uses[i].agent });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const quotes = [...asked.values()];
|
|
88
|
+
const quoted = quotes.length
|
|
31
89
|
? await ctx.call("usage.quotes", {
|
|
32
|
-
uses:
|
|
90
|
+
uses: quotes.map(({ id, agent }) => {
|
|
33
91
|
const slash = id.indexOf("/");
|
|
34
92
|
const from = declared[id.slice(0, slash)]?.catalog;
|
|
35
93
|
return {
|
|
36
94
|
meter: "llm",
|
|
37
95
|
subject: id,
|
|
38
96
|
catalog: `${typeof from === "string" ? from : id.slice(0, slash)}${id.slice(slash)}`,
|
|
39
|
-
quantities:
|
|
97
|
+
quantities: callOf(agent),
|
|
40
98
|
};
|
|
41
99
|
}),
|
|
42
|
-
}).catch(() =>
|
|
100
|
+
}).catch(() => quotes.map(() => null))
|
|
43
101
|
: [];
|
|
44
|
-
const prices = new Map(
|
|
45
|
-
return
|
|
102
|
+
const prices = new Map([...asked.keys()].map((key, i) => [key, quoted[i] ?? null]));
|
|
103
|
+
return lists.map((list, i) => {
|
|
104
|
+
const p = list[0];
|
|
46
105
|
if (!p)
|
|
47
106
|
return undefined;
|
|
48
107
|
const info = known.get(p.id);
|
|
108
|
+
const agent = uses[i].agent;
|
|
109
|
+
// The first that costs something: one that's free here is a plan the person brings.
|
|
110
|
+
const each = charged[i].map((entry) => prices.get(keyOf(entry.id, agent)) ?? null);
|
|
111
|
+
const call = each.find((price) => price !== null && price > 0) ??
|
|
112
|
+
each.find((price) => price !== null) ?? null;
|
|
113
|
+
const calls = typical ? typical[agent]?.calls ?? 0 : 1;
|
|
114
|
+
const named = (id) => known.get(id)?.name ?? id.slice(id.indexOf("/") + 1);
|
|
49
115
|
return {
|
|
50
116
|
id: p.id,
|
|
51
|
-
name:
|
|
117
|
+
name: named(p.id),
|
|
52
118
|
...(p.effort ? { effort: p.effort } : {}),
|
|
53
|
-
price:
|
|
54
|
-
...(info?.ownKey ? { ownKey: true } : {}),
|
|
119
|
+
price: call === null ? null : call * calls,
|
|
120
|
+
...(info?.ownKey && !charged[i].length ? { ownKey: true } : {}),
|
|
121
|
+
...(list.length > 1
|
|
122
|
+
? {
|
|
123
|
+
fallbacks: list.slice(1).map((entry) => ({
|
|
124
|
+
id: entry.id,
|
|
125
|
+
name: named(entry.id),
|
|
126
|
+
...(entry.effort ? { effort: entry.effort } : {}),
|
|
127
|
+
})),
|
|
128
|
+
}
|
|
129
|
+
: {}),
|
|
55
130
|
};
|
|
56
131
|
});
|
|
57
132
|
}
|
|
58
|
-
/**
|
|
59
|
-
const
|
|
133
|
+
/** What's priced, summed (a message) or averaged (a reply); null when nothing is. */
|
|
134
|
+
const total = (prices, per) => {
|
|
60
135
|
const priced = prices.filter((p) => p !== null);
|
|
61
|
-
|
|
136
|
+
if (!priced.length)
|
|
137
|
+
return null;
|
|
138
|
+
const sum = priced.reduce((a, b) => a + b, 0);
|
|
139
|
+
return per === "message" ? sum : sum / priced.length;
|
|
62
140
|
};
|
|
63
|
-
/** Everything a page shows, at the org's level, or a space
|
|
64
|
-
export async function shownAt(ctx,
|
|
65
|
-
const
|
|
66
|
-
|
|
141
|
+
/** Everything a page shows, at the org's level, or where asked (a space, a conversation). */
|
|
142
|
+
export async function shownAt(ctx, where = {}) {
|
|
143
|
+
const person = personOf(ctx.actor);
|
|
144
|
+
const [{ tiers, kinds, templates }, levels, credits] = await Promise.all([
|
|
145
|
+
orgTiersOf(ctx),
|
|
146
|
+
levelsOf(ctx, { ...where, ...(person ? { person } : {}) }),
|
|
147
|
+
creditsOf(ctx),
|
|
148
|
+
]);
|
|
149
|
+
const per = typicalOf(ctx) ? "message" : "reply";
|
|
67
150
|
const agents = agentsOf(ctx);
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
151
|
+
const kindNames = Object.keys(kinds);
|
|
152
|
+
const list = Object.entries(tiers);
|
|
153
|
+
// Every tier's chain for every kind, asked for at once, and taken back in the same order.
|
|
154
|
+
const uses = list.flatMap(([, tier]) => kindNames.flatMap((kind) => {
|
|
155
|
+
const ref = entryOf(tier, kind, kinds);
|
|
156
|
+
return ref === undefined ? [] : [{ ref, agent: kinds[kind].base ?? kind }];
|
|
73
157
|
}));
|
|
74
|
-
const
|
|
75
|
-
// Every model shown, asked for at once, and taken back in the same order.
|
|
76
|
-
const refs = [
|
|
77
|
-
...tiers.flatMap(([, tier]) => Object.values(tier.agents)),
|
|
78
|
-
...custom(levels.org).map(([, ref]) => ref),
|
|
79
|
-
...custom(levels.space).map(([, ref]) => ref),
|
|
80
|
-
...now.map((n) => n.model ?? modelOf(agents[n.agent])),
|
|
81
|
-
];
|
|
82
|
-
const shown = await modelsShown(ctx, refs);
|
|
158
|
+
const shown = await modelsShown(ctx, uses);
|
|
83
159
|
let cursor = 0;
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const listed = Object.keys(tier.agents).map((agent) => ({ agent, model: next() }))
|
|
87
|
-
.filter((a) => !!a.model && !!agents[a.agent]);
|
|
160
|
+
const tiersShown = list.map(([name, tier]) => {
|
|
161
|
+
const own = kindNames.flatMap((kind) => entryOf(tier, kind, kinds) === undefined ? [] : [{ kind, model: shown[cursor++] }]).filter((k) => !!k.model);
|
|
88
162
|
return {
|
|
89
163
|
name,
|
|
90
164
|
title: tier.title,
|
|
91
165
|
...(tier.description ? { description: tier.description } : {}),
|
|
92
|
-
|
|
93
|
-
|
|
166
|
+
// Only the app's kinds count toward a typical message: an org's own is extra.
|
|
167
|
+
price: total(own.filter((k) => !kinds[k.kind].base).map((k) => k.model.price), per),
|
|
168
|
+
...(tier.app ? { app: true } : {}),
|
|
169
|
+
...(tier.changed ? { changed: true } : {}),
|
|
170
|
+
...(tier.made ? { made: true } : {}),
|
|
171
|
+
kinds: own,
|
|
94
172
|
};
|
|
95
173
|
});
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const model = next();
|
|
100
|
-
return model ? [[agent, model]] : [];
|
|
101
|
-
})),
|
|
102
|
-
});
|
|
103
|
-
const org = choiceShown(levels.org);
|
|
104
|
-
const here = space ? choiceShown(levels.space) : undefined;
|
|
105
|
-
const inForce = tierIn(tiersOf(ctx), levels);
|
|
174
|
+
const offered = (name) => name && tiers[name] ? name : null;
|
|
175
|
+
const app = (ctx.resources.tiers ?? {});
|
|
176
|
+
const inForce = tierIn(tiers, levels);
|
|
106
177
|
return {
|
|
107
178
|
tiers: tiersShown,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const model = next();
|
|
120
|
-
return model ? [[n.agent, { model, from: titled(ctx, n.from) }]] : [];
|
|
179
|
+
kinds: kindNames.map((kind) => ({
|
|
180
|
+
kind,
|
|
181
|
+
title: kinds[kind].title,
|
|
182
|
+
...(kinds[kind].description ? { description: kinds[kind].description } : {}),
|
|
183
|
+
...(kinds[kind].base ? { base: kinds[kind].base } : {}),
|
|
184
|
+
agents: Object.entries(agents)
|
|
185
|
+
.filter(([name, def]) => kindOf(ctx, name, def.like, kinds) === kind && agents[name].default)
|
|
186
|
+
.map(([name, def]) => ({
|
|
187
|
+
agent: name,
|
|
188
|
+
name: def.name ?? name[0].toUpperCase() + name.slice(1),
|
|
189
|
+
...(def.icon ? { icon: def.icon } : {}),
|
|
121
190
|
})),
|
|
122
|
-
},
|
|
191
|
+
})),
|
|
192
|
+
removed: templates.filter((t) => t.off && app[t._id])
|
|
193
|
+
.map((t) => ({ name: t._id, title: app[t._id].title })),
|
|
194
|
+
plan: offered(levels.plan),
|
|
195
|
+
org: { tier: offered(levels.org?.tier), cap: offered(levels.org?.cap) },
|
|
196
|
+
...(where.space ? { space: { tier: offered(levels.space?.tier) } } : {}),
|
|
197
|
+
...(where.thread ? { thread: { tier: offered(levels.thread?.tier) } } : {}),
|
|
198
|
+
person: { tier: offered(levels.person?.tier) },
|
|
199
|
+
now: inForce ?? null,
|
|
200
|
+
per,
|
|
123
201
|
reply: REPLY,
|
|
202
|
+
credits,
|
|
124
203
|
};
|
|
125
204
|
}
|
|
126
|
-
/**
|
|
127
|
-
|
|
205
|
+
/** Which of the app's kinds one people made works as, as chat's `agentSources` say. */
|
|
206
|
+
async function likeOf(ctx, agent) {
|
|
207
|
+
const sources = Object.values((ctx.resources.agentSources ?? {}));
|
|
208
|
+
for (const source of sources) {
|
|
209
|
+
const told = await ctx.call(source.action, {
|
|
210
|
+
names: [agent],
|
|
211
|
+
})
|
|
212
|
+
.catch(() => ({}));
|
|
213
|
+
if (told[agent])
|
|
214
|
+
return told[agent].like;
|
|
215
|
+
}
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
128
218
|
/**
|
|
129
|
-
* One
|
|
130
|
-
*
|
|
131
|
-
*
|
|
219
|
+
* One agent where it works (a space, maybe a conversation): its kind of work,
|
|
220
|
+
* the tier in force there and who chose it, and its chain in that tier; null
|
|
221
|
+
* when no tier applies.
|
|
132
222
|
*/
|
|
133
|
-
export async function agentAt(ctx, agent,
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const now = resolve(ctx, agent, levels);
|
|
139
|
-
const picked = levels.space?.custom?.[agent] !== undefined;
|
|
140
|
-
const { [agent]: _, ...others } = levels.space?.custom ?? {};
|
|
141
|
-
const before = picked
|
|
142
|
-
? resolve(ctx, agent, { ...levels, space: { ...levels.space, custom: others } })
|
|
143
|
-
: undefined;
|
|
144
|
-
const [shown, without] = await modelsShown(ctx, [
|
|
145
|
-
await carried(ctx, now) ?? modelOf(own),
|
|
146
|
-
...(before ? [await carried(ctx, before) ?? modelOf(own)] : []),
|
|
223
|
+
export async function agentAt(ctx, agent, where) {
|
|
224
|
+
const person = personOf(ctx.actor);
|
|
225
|
+
const [{ tiers, kinds }, levels] = await Promise.all([
|
|
226
|
+
orgTiersOf(ctx),
|
|
227
|
+
levelsOf(ctx, { ...where, ...(person ? { person } : {}) }),
|
|
147
228
|
]);
|
|
148
|
-
|
|
229
|
+
const declared = agentsOf(ctx)[agent];
|
|
230
|
+
const like = declared ? declared.like : await likeOf(ctx, agent);
|
|
231
|
+
const kind = kindOf(ctx, agent, like, kinds);
|
|
232
|
+
const inForce = tierIn(tiers, levels);
|
|
233
|
+
if (!kind || !inForce)
|
|
234
|
+
return null;
|
|
235
|
+
const ref = entryOf(tiers[inForce.tier], kind, kinds);
|
|
236
|
+
if (ref === undefined)
|
|
237
|
+
return null;
|
|
238
|
+
const [model] = await modelsShown(ctx, [{ ref, agent: kinds[kind].base ?? kind }]);
|
|
239
|
+
if (!model)
|
|
149
240
|
return null;
|
|
150
241
|
return {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
242
|
+
kind,
|
|
243
|
+
kindTitle: kinds[kind].title,
|
|
244
|
+
tier: inForce.tier,
|
|
245
|
+
tierTitle: tiers[inForce.tier].title,
|
|
246
|
+
by: inForce.by,
|
|
247
|
+
model,
|
|
154
248
|
};
|
|
155
249
|
}
|
package/tiers/shared/tiers.d.ts
CHANGED
|
@@ -1,88 +1,133 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tiers,
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Tiers as templates, worked out the same way for a turn and for a page. Only
|
|
3
|
+
* plain data in and out: no reads here.
|
|
4
|
+
*
|
|
5
|
+
* - **A kind of work** (`north`, as the app calls it, titled "Decides") is
|
|
6
|
+
* what an agent does, as far as its model goes. The app's kinds are its
|
|
7
|
+
* tiers' keys, titled by its `tierKinds` resource; an org adds its own,
|
|
8
|
+
* each based on one of the app's (`tierKind`). Every agent has one: one of
|
|
9
|
+
* the app's agents is its own kind when the tiers name it; any other says
|
|
10
|
+
* which (`like`), else it's the app's first.
|
|
11
|
+
* - **A tier** is a template: for each kind of work, a model chain (as an
|
|
12
|
+
* agent's `model` takes one: a model, settings around one, or a list tried
|
|
13
|
+
* in order). The app declares its tiers (`tiers`); an org keeps its own
|
|
14
|
+
* version of one (`tierTemplate`: kinds' chains changed, or `off`, taken
|
|
15
|
+
* away) and makes new ones (`made`). A kind a tier doesn't name takes its
|
|
16
|
+
* base kind's chain there.
|
|
17
|
+
* - **Which tier a turn uses**, the first that applies: the conversation's,
|
|
18
|
+
* the person's own default for new chats, the space's, the org's, the
|
|
19
|
+
* plan's (`modelChoice`).
|
|
6
20
|
*/
|
|
7
21
|
import type { Resources } from "copilotz";
|
|
8
22
|
import type { ModelRef } from "copilotz/plugins/models/contract";
|
|
9
|
-
/** A tier: a model for each of
|
|
23
|
+
/** A tier: a model chain for each kind of work, named by what it's good for. */
|
|
10
24
|
export type Tier = {
|
|
11
25
|
title: string;
|
|
12
26
|
/** What it's good for, in a line: "Quick answers, routine work, volume". */
|
|
13
27
|
description?: string;
|
|
14
28
|
/** Among the tiers, lowest first. */
|
|
15
29
|
order?: number;
|
|
16
|
-
/** Each
|
|
30
|
+
/** Each kind of work's chain, by kind, as an agent's `model` takes it. */
|
|
17
31
|
agents: Record<string, ModelRef>;
|
|
18
32
|
};
|
|
19
|
-
/**
|
|
33
|
+
/** A tier as the org has it: the app's (as it is, or `changed`), or one the org `made`. */
|
|
34
|
+
export type OrgTier = Tier & {
|
|
35
|
+
app?: true;
|
|
36
|
+
changed?: true;
|
|
37
|
+
made?: true;
|
|
38
|
+
};
|
|
39
|
+
/** What an org keeps of a tier: its version of the app's (or that it took it away), or one it made. */
|
|
40
|
+
export type Template = {
|
|
41
|
+
_id: string;
|
|
42
|
+
title?: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
order?: number;
|
|
45
|
+
agents?: Record<string, ModelRef>;
|
|
46
|
+
/** One of the app's the org took away. */
|
|
47
|
+
off?: boolean;
|
|
48
|
+
/** One the org made. */
|
|
49
|
+
made?: boolean;
|
|
50
|
+
at: string;
|
|
51
|
+
};
|
|
52
|
+
/** A kind of work: what it's called, and for one an org added, the app's kind it starts from. */
|
|
53
|
+
export type Kind = {
|
|
54
|
+
title: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
base?: string;
|
|
57
|
+
};
|
|
58
|
+
/** One an org added (`tierKind`), by its name. */
|
|
59
|
+
export type OrgKind = {
|
|
60
|
+
_id: string;
|
|
61
|
+
title: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
base: string;
|
|
64
|
+
at: string;
|
|
65
|
+
};
|
|
66
|
+
/** What a level chose: a tier by its name; the org's also the highest tier its members may use. */
|
|
20
67
|
export type Choice = {
|
|
21
68
|
tier?: string;
|
|
22
|
-
|
|
69
|
+
cap?: string;
|
|
23
70
|
};
|
|
24
|
-
/** Where a choice is kept
|
|
71
|
+
/** Where a choice is kept. */
|
|
25
72
|
export declare const ORG_CHOICE = "org";
|
|
26
73
|
export declare const spaceChoice: (space: string) => string;
|
|
27
|
-
|
|
28
|
-
export declare const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
export type From = {
|
|
33
|
-
by: "space" | "org";
|
|
34
|
-
custom: true;
|
|
35
|
-
tier?: string;
|
|
36
|
-
} | {
|
|
37
|
-
by: "space" | "org" | "plan";
|
|
38
|
-
tier: string;
|
|
39
|
-
} | {
|
|
40
|
-
by: "app";
|
|
41
|
-
};
|
|
42
|
-
/** What applies, at one level and those above it: each a choice, or none. */
|
|
74
|
+
export declare const threadChoice: (thread: string) => string;
|
|
75
|
+
export declare const personChoice: (person: string) => string;
|
|
76
|
+
/** Who chose the tier in force. */
|
|
77
|
+
export type By = "thread" | "person" | "space" | "org" | "plan";
|
|
78
|
+
/** What applies, at each level: each a choice, or none. */
|
|
43
79
|
export type Levels = {
|
|
80
|
+
thread?: Choice | null;
|
|
81
|
+
person?: Choice | null;
|
|
44
82
|
space?: Choice | null;
|
|
45
83
|
org?: Choice | null;
|
|
46
84
|
plan?: string | null;
|
|
47
85
|
};
|
|
48
|
-
/** The
|
|
49
|
-
export declare
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
86
|
+
/** The app's tiers, as it declares them. */
|
|
87
|
+
export declare const appTiersOf: (ctx: {
|
|
88
|
+
resources: Resources;
|
|
89
|
+
}) => Record<string, Tier>;
|
|
90
|
+
/** The app's kinds of work: its tiers' keys, in the order its agents are declared, titled. */
|
|
91
|
+
export declare function appKindsOf(ctx: {
|
|
92
|
+
resources: Resources;
|
|
93
|
+
}): Record<string, Kind>;
|
|
94
|
+
/** Every kind of work: the app's, then those the org added (on an app's kind still there). */
|
|
95
|
+
export declare function kindsIn(ctx: {
|
|
96
|
+
resources: Resources;
|
|
97
|
+
}, own: OrgKind[]): Record<string, Kind>;
|
|
98
|
+
/** The kind an agent works as: what it says (`like`); its own, where tiers name it; else the app's first. */
|
|
99
|
+
export declare function kindOf(ctx: {
|
|
100
|
+
resources: Resources;
|
|
101
|
+
}, name: string, like: string | undefined, kinds: Record<string, Kind>): string | undefined;
|
|
64
102
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* agent leaves it on its own model; so does nothing chosen (`model` null).
|
|
69
|
-
* A pick keeps the list it stands in front of behind it (the tier in force
|
|
70
|
-
* below it, or the agent's own), so a model that fails falls back as before;
|
|
71
|
-
* `carried` gives it that entry's settings. An agent that isn't the app's is
|
|
72
|
-
* none of this: null.
|
|
103
|
+
* The org's tiers: the app's as the org keeps them (its version over them,
|
|
104
|
+
* those it took away left out), then those it made; each by its name, in
|
|
105
|
+
* order.
|
|
73
106
|
*/
|
|
74
|
-
export declare function
|
|
107
|
+
export declare function tiersIn(ctx: {
|
|
75
108
|
resources: Resources;
|
|
76
|
-
},
|
|
109
|
+
}, templates: Template[]): Record<string, OrgTier>;
|
|
110
|
+
/** A kind's chain in a tier: its own entry there, else its base kind's. */
|
|
111
|
+
export declare function entryOf(tier: Tier | undefined, kind: string | undefined, kinds: Record<string, Kind>): ModelRef | undefined;
|
|
112
|
+
/** The tier in force, and who chose it: the conversation, the person, the space, the org, the plan. */
|
|
113
|
+
export declare function tierIn(tiers: Record<string, unknown>, levels: Levels): {
|
|
114
|
+
tier: string;
|
|
115
|
+
by: By;
|
|
116
|
+
} | undefined;
|
|
117
|
+
/** Whether a tier is above the highest the org lets its members use (`cap`). */
|
|
118
|
+
export declare function aboveCap(tiers: Record<string, unknown>, tier: string, cap?: string): boolean;
|
|
119
|
+
/** A model, as a list: what's tried in order. */
|
|
120
|
+
export declare const listOf: (ref: ModelRef) => ModelRef[];
|
|
121
|
+
/** The model a ref tries first, as `"provider/model"` when it says so plainly. */
|
|
122
|
+
export declare const firstId: (ref: ModelRef) => string | undefined;
|
|
77
123
|
/** What a model's first choice is set to think and write with. */
|
|
78
|
-
type Settings = {
|
|
124
|
+
export type Settings = {
|
|
79
125
|
effort?: string;
|
|
80
126
|
maxTokens?: number;
|
|
81
127
|
};
|
|
82
128
|
/**
|
|
83
129
|
* The model a ref tries first, with the effort and most tokens it's asked
|
|
84
|
-
* for, following aliases (`resources.model`): what a page shows of it
|
|
85
|
-
* what a pick carries over.
|
|
130
|
+
* for, following aliases (`resources.model`): what a page shows of it.
|
|
86
131
|
*/
|
|
87
132
|
export declare function primaryOf(ctx: {
|
|
88
133
|
resources: Resources;
|
|
@@ -90,14 +135,12 @@ export declare function primaryOf(ctx: {
|
|
|
90
135
|
id: string;
|
|
91
136
|
} & Settings) | undefined;
|
|
92
137
|
/**
|
|
93
|
-
*
|
|
94
|
-
* its `maxTokens`, and its `effort`
|
|
95
|
-
* (the catalog's, `models.efforts`)
|
|
96
|
-
*
|
|
97
|
-
* pick sets itself wins.
|
|
138
|
+
* A chain someone set on a page (each entry a model), with what the chain it
|
|
139
|
+
* replaces sets on its first entry: its `maxTokens`, and its `effort` where
|
|
140
|
+
* each model takes it and none was said (the catalog's, `models.efforts`).
|
|
141
|
+
* So a chain set by hand isn't cut short by an adapter's default.
|
|
98
142
|
*/
|
|
99
|
-
export declare function
|
|
143
|
+
export declare function settled(ctx: {
|
|
100
144
|
resources: Resources;
|
|
101
145
|
call<R>(action: string, input?: unknown): Promise<R>;
|
|
102
|
-
},
|
|
103
|
-
export {};
|
|
146
|
+
}, chain: ModelRef[], like: ModelRef | undefined): Promise<ModelRef[]>;
|