@intentic/sandbox-contract 1.246.1 → 1.247.0

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 (75) hide show
  1. package/dist/batch-runs.d.ts +2 -0
  2. package/dist/batch-runs.d.ts.map +1 -1
  3. package/dist/batch-runs.js +1 -0
  4. package/dist/batch-runs.js.map +1 -1
  5. package/dist/contracts/agent.contract.d.ts +19 -0
  6. package/dist/contracts/agent.contract.d.ts.map +1 -1
  7. package/dist/contracts/settings.contract.d.ts +97 -10
  8. package/dist/contracts/settings.contract.d.ts.map +1 -1
  9. package/dist/contracts/usage.contract.d.ts +22 -0
  10. package/dist/contracts/usage.contract.d.ts.map +1 -1
  11. package/dist/contracts/usage.contract.js +19 -0
  12. package/dist/contracts/usage.contract.js.map +1 -1
  13. package/dist/definition.d.ts +16 -20
  14. package/dist/definition.d.ts.map +1 -1
  15. package/dist/fast-tier.js +1 -1
  16. package/dist/fast-tier.js.map +1 -1
  17. package/dist/index.d.ts +140 -12
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/model-pins.d.ts +17 -0
  22. package/dist/model-pins.d.ts.map +1 -0
  23. package/dist/{quick-model.js → model-pins.js} +16 -10
  24. package/dist/model-pins.js.map +1 -0
  25. package/dist/model-roles.d.ts +144 -0
  26. package/dist/model-roles.d.ts.map +1 -0
  27. package/dist/model-roles.js +129 -0
  28. package/dist/model-roles.js.map +1 -0
  29. package/dist/schemas/agent.d.ts +21 -2
  30. package/dist/schemas/agent.d.ts.map +1 -1
  31. package/dist/schemas/agent.js +4 -2
  32. package/dist/schemas/agent.js.map +1 -1
  33. package/dist/schemas/plan-limits.d.ts +20 -0
  34. package/dist/schemas/plan-limits.d.ts.map +1 -1
  35. package/dist/schemas/plan-limits.js +21 -0
  36. package/dist/schemas/plan-limits.js.map +1 -1
  37. package/dist/schemas/settings.d.ts +82 -5
  38. package/dist/schemas/settings.d.ts.map +1 -1
  39. package/dist/schemas/settings.js +15 -18
  40. package/dist/schemas/settings.js.map +1 -1
  41. package/dist/schemas/usage.d.ts +5 -0
  42. package/dist/schemas/usage.d.ts.map +1 -1
  43. package/dist/schemas/usage.js +5 -0
  44. package/dist/schemas/usage.js.map +1 -1
  45. package/package.json +4 -4
  46. package/src/agent-catalog.ts +1 -1
  47. package/src/batch-runs.test.ts +10 -5
  48. package/src/batch-runs.ts +10 -3
  49. package/src/contracts/usage.contract.ts +31 -0
  50. package/src/events.ts +1 -1
  51. package/src/fast-tier.test.ts +1 -1
  52. package/src/fast-tier.ts +5 -5
  53. package/src/index.ts +2 -2
  54. package/src/{quick-model.test.ts → model-pins.test.ts} +73 -29
  55. package/src/model-pins.ts +183 -0
  56. package/src/model-roles.ts +224 -0
  57. package/src/plan-pools.ts +1 -1
  58. package/src/prompt-complexity.test.ts +1 -1
  59. package/src/prompt-complexity.ts +2 -2
  60. package/src/provider-specs.test.ts +1 -1
  61. package/src/schemas/agent.ts +42 -17
  62. package/src/schemas/agents.ts +2 -2
  63. package/src/schemas/plan-limits.ts +50 -0
  64. package/src/schemas/settings.ts +77 -88
  65. package/src/schemas/usage.ts +59 -0
  66. package/dist/agent-run-model.d.ts +0 -4
  67. package/dist/agent-run-model.d.ts.map +0 -1
  68. package/dist/agent-run-model.js +0 -13
  69. package/dist/agent-run-model.js.map +0 -1
  70. package/dist/quick-model.d.ts +0 -15
  71. package/dist/quick-model.d.ts.map +0 -1
  72. package/dist/quick-model.js.map +0 -1
  73. package/src/agent-run-model.test.ts +0 -76
  74. package/src/agent-run-model.ts +0 -65
  75. package/src/quick-model.ts +0 -162
@@ -1,162 +0,0 @@
1
- import { accessFor, modelsFor, PROVIDERS } from "./agent-catalog.js";
2
- import { ACCESS_COST } from "./provider-specs.js";
3
- import { compareCheapestFirst, familyOf, tierRankOf } from "./model-order.js";
4
- import type { AgentProvider } from "./schemas/agent.js";
5
-
6
- /* THE QUICK MODEL, the cheap, fast model a small automatic job spends instead of the frontier model the chat
7
- * runs on. Today that is the commit message written when an agent's work lands; anything else of that shape (a
8
- * branch name, a PR description) reads the same answer, which is the reason this is a `quickModel` setting
9
- * rather than a commit-message one.
10
- *
11
- * IT IS AN ORDER, NOT A MODEL, and that is the whole shape of this file. A single pick is a single point of
12
- * failure: the account it names spends its allowance on the chat all morning, and every job for the rest of the
13
- * day fails on a limit while three other connected providers sit idle. So the setting is a LIST
14
- * read top to bottom, the resolver hands back the whole ladder, and the daemon walks it until one answers.
15
- * Nothing here decides WHICH failures are worth stepping over, that is the daemon's, since only it has run
16
- * the call, this side only says what the running order is.
17
- *
18
- * The rule lives in the contract because BOTH sides need the same answer for different jobs: the daemon runs
19
- * the model, and the browser has to NAME it, in the settings row's "Auto (…)" label, before anything has been
20
- * run. Two implementations would drift precisely where it matters most, since a label promising Haiku while the
21
- * daemon bills Opus is worse than no label.
22
- *
23
- * The default is DERIVED, NEVER STORED. `quickModel` ships EMPTY and that means "work it out from whatever is
24
- * connected right now", so connecting a Google account tomorrow improves the default by itself and
25
- * disconnecting a pinned provider degrades to Auto instead of to a dead button. Same instinct as the rest of
26
- * this repo's model handling: model-order.ts derives tier and recency from the id and curates nothing, and the
27
- * web's defaultModelFor reads the live catalog rather than naming an id that a release will falsify. */
28
-
29
- /* One provider's standing in the decision: whether a turn on it can be sent at all, and what its catalog holds.
30
- *
31
- * ACP agents are deliberately not expressible here, an ACP row's model id is empty because the agent owns its
32
- * own model, so there is no cheap rung to point it at. `endpoint/<id>` providers ARE, and have to be: their
33
- * models appear in the same picker the settings row builds its options from, so a pin naming one has to hold
34
- * rather than fall silently back to Auto and spend an account the user was deliberately steering away from. */
35
- export interface QuickModelSource {
36
- // AgentProvider, not NativeProvider: an endpoint's id is user-created and cannot be in a fixed union. Auto's
37
- // ranking degrades gracefully for one, costOf falls to the metered rung and an id with no tier word is
38
- // UNRANKED, which is genuine last place, so an endpoint effectively only wins Auto when nothing else is
39
- // connected, while a PIN on one holds. Both are the right answers: what a turn on someone's own model server
40
- // costs is not a fact this repo can know, so it is not one Auto should be asserting.
41
- readonly provider: AgentProvider;
42
- // The same connection predicate every other surface gates on (access.ts web-side, the daemon's own account
43
- // stores daemon-side). A catalog is never empty by construction, so "has rows" says nothing about "can send".
44
- readonly ready: boolean;
45
- readonly models: readonly string[];
46
- }
47
-
48
- export interface QuickModelChoice {
49
- readonly provider: AgentProvider;
50
- readonly model: string;
51
- }
52
-
53
- // A pinned selection on the wire: `${provider}:${modelId}`, the same key shape the model picker already mints
54
- // for its entries (PickerEntry.key). An empty LIST of these ⇒ Auto.
55
- export const quickModelKey = (choice: QuickModelChoice): string => `${choice.provider}:${choice.model}`;
56
-
57
- /* Split on the FIRST colon only: a provider id never contains one and a model id might. Exported because the
58
- * key is what several surfaces carry a pinned pair AS: `autoFastModels` stores the same keys, the settings rows
59
- * read one back to draw the model they name, and a session composed from a pin travels as one (composeSession).
60
- *
61
- * `agentRunModels` is the one list that does NOT: an agent-run entry is an object, because it carries how the
62
- * model is to be run beside which model it is (AgentRunPinSchema), and a key with knobs spelled into it would
63
- * be a second encoding of the same thing for nobody's benefit. */
64
- export const parsePinned = (pinned: string): QuickModelChoice | undefined => {
65
- const separator = pinned.indexOf(`:`);
66
- if (separator <= 0 || separator === pinned.length - 1) {
67
- return undefined;
68
- }
69
- return { provider: pinned.slice(0, separator), model: pinned.slice(separator + 1) };
70
- };
71
-
72
- /* A pin as a person reads it: the catalog's own label for the id, or the id itself for one the static catalog
73
- * has not caught up with (the picker offers a custom-id escape hatch, so this is a real case rather than a
74
- * defensive branch). Beside parsePinned because the two are always wanted together, by any surface that has to
75
- * name what a click is about to spend BEFORE it spends it, and the two loudest of those are extensions that
76
- * share no other code with each other. */
77
- export const pinnedModelLabel = (choice: QuickModelChoice): string =>
78
- modelsFor(choice.provider).find((option) => option.value === choice.model)?.label ?? choice.model;
79
-
80
- // The cheapest row a provider publishes, its whole catalog read from the cheap end. Undefined for a catalog
81
- // that hasn't loaded yet, which is a real state: every provider serves a floor, but only once something has
82
- // asked it.
83
- const cheapestOf = (source: QuickModelSource): string | undefined => source.models.toSorted(compareCheapestFirst)[0];
84
-
85
- // Where a provider's cheapest row sits on the shared tier scale, and therefore how well it answers the question
86
- // this whole module asks. UNRANKED (-1) is a genuine last place: it means the id carries no tier word we know,
87
- // so the row is the provider's base line rather than its budget one.
88
- const tierOf = (model: string): number => tierRankOf(familyOf(model));
89
-
90
- // PROVIDERS order, as the final tiebreak. Arbitrary, but the SAME arbitrary answer on every read, the property
91
- // compareUnrankedModelIds exists to guarantee, and the one a default actually needs. An endpoint is in no fixed
92
- // list, so it reads -1 and leads the tiebreak; unreachable in practice, since it can never tie on cost.
93
- const providerOrder = (provider: AgentProvider): number => PROVIDERS.findIndex((entry) => entry.value === provider);
94
-
95
- /* WHAT AN ENDPOINT COSTS, one rung past every provider's, and the reason it is a number here rather than a
96
- * member of AccessKind. That axis describes the providers this repo ships, and every one of them is unlocked by
97
- * signing in to something the user already holds, so none of them is metered per call. An endpoint is the
98
- * opposite: whatever gateway somebody pointed us at, whose bill this repo cannot see. Reading it as dearer than
99
- * anything on the table is the conservative answer, and it is what keeps Auto from reaching for a paid gateway
100
- * on its own initiative. */
101
- const METERED_COST = Math.max(...Object.values(ACCESS_COST)) + 1;
102
-
103
- // How much a call on this provider costs at the margin. Every native provider declares an access kind; an
104
- // endpoint declares none, and takes the metered rung above.
105
- const costOf = (provider: AgentProvider): number => {
106
- const access = accessFor(provider);
107
- return access === undefined ? METERED_COST : ACCESS_COST[access.kind];
108
- };
109
-
110
- /* AUTO, every connected provider's cheapest row, best-first, as a ladder rather than a winner.
111
- *
112
- * Ranked on TIER FIRST, then cost. That order is the point of the feature: the helper exists to not be the
113
- * frontier model, so a free flagship is still the wrong tool, while a free Haiku-class row and a subscription
114
- * Haiku-class row differ only in whose quota they spend. Cost then breaks that tie towards the channel the user
115
- * is not paying per token for, and against the one they are.
116
- *
117
- * The whole ladder, not just its head, because the same ranking that picks the best answer also states the best
118
- * SECOND answer, and a sandbox with three accounts connected should not lose its commit messages for six hours
119
- * because one of them is spent. */
120
- const autoLadder = (sources: readonly QuickModelSource[]): readonly QuickModelChoice[] =>
121
- sources
122
- .filter((source) => source.ready)
123
- .flatMap((source) => {
124
- const model = cheapestOf(source);
125
- return model === undefined ? [] : [{ provider: source.provider, model }];
126
- })
127
- .toSorted(
128
- (left, right) =>
129
- tierOf(right.model) - tierOf(left.model) ||
130
- costOf(left.provider) - costOf(right.provider) ||
131
- providerOrder(left.provider) - providerOrder(right.provider),
132
- );
133
-
134
- /* WHICH MODELS A QUICK HELPER MAY RUN, IN THE ORDER IT SHOULD TRY THEM, given what this sandbox has connected.
135
- * `pinned` is the stored setting: an ordered list of `${provider}:${model}` keys, empty for Auto.
136
- *
137
- * A pin only holds while its provider is READY: an account the user disconnected would otherwise sit at the
138
- * head of the chain failing on a credential error, when the sandbox can plainly still answer. Dropping it is
139
- * the same move the composer already makes when a live catalog stops offering the selected model.
140
- *
141
- * THE PINNED LIST IS THE WHOLE ANSWER whenever any of it survives that filter. Auto does NOT get appended
142
- * underneath, and that is deliberate: a user who writes down three models has said which accounts this feature
143
- * may spend, and quietly reaching for a fourth when all three are out is exactly the "spend an account they
144
- * were steering away from" failure a pin exists to prevent. When NONE of the pins is connected any more the
145
- * list has stopped saying anything about this sandbox, so Auto takes over rather than leaving a dead button.
146
- *
147
- * Empty when nothing is connected: the caller renders a control that says so, rather than a live button that
148
- * fails on click. */
149
- export const resolveQuickModels = (sources: readonly QuickModelSource[], pinned: readonly string[]): readonly QuickModelChoice[] => {
150
- const ready = new Set(sources.filter((source) => source.ready).map((source) => source.provider));
151
- const requested = pinned.flatMap((key) => {
152
- // Taken verbatim, unvalidated against the catalog on purpose: the picker already offers a custom-id
153
- // escape hatch for a model a catalog hasn't caught up with, and second-guessing the user's own id here
154
- // would silently run a different model than the settings row names.
155
- const choice = parsePinned(key);
156
- return choice === undefined || !ready.has(choice.provider) ? [] : [choice];
157
- });
158
- // The same model twice would spend two attempts proving the same account is out, a real state, since the
159
- // list is edited by hand and Auto's ladder can rank a provider the user has also pinned.
160
- const chain = [...new Map(requested.map((choice) => [quickModelKey(choice), choice])).values()];
161
- return chain.length > 0 ? chain : autoLadder(sources);
162
- };