@genesislcap/ai-assistant 15.107.0 → 15.109.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 (61) hide show
  1. package/dist/ai-assistant.api.json +410 -4
  2. package/dist/ai-assistant.d.ts +121 -2
  3. package/dist/chat-driver.cjs +69 -18
  4. package/dist/chat-driver.cjs.map +2 -2
  5. package/dist/chat-driver.mjs +69 -18
  6. package/dist/chat-driver.mjs.map +2 -2
  7. package/dist/custom-elements.json +787 -578
  8. package/dist/dts/chat-driver-node.d.ts +1 -1
  9. package/dist/dts/chat-driver-node.d.ts.map +1 -1
  10. package/dist/dts/components/chat-driver/chat-driver.d.ts +9 -0
  11. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  12. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +2 -0
  13. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  14. package/dist/dts/components/settings-modal/settings-modal.d.ts +2 -0
  15. package/dist/dts/components/settings-modal/settings-modal.d.ts.map +1 -1
  16. package/dist/dts/components/settings-modal/settings-modal.styles.d.ts.map +1 -1
  17. package/dist/dts/components/settings-modal/settings-modal.template.d.ts +1 -0
  18. package/dist/dts/components/settings-modal/settings-modal.template.d.ts.map +1 -1
  19. package/dist/dts/genesis/config.d.ts.map +1 -1
  20. package/dist/dts/genesis/register-genesis-assistant.d.ts +24 -0
  21. package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
  22. package/dist/dts/genesis/types.d.ts +8 -2
  23. package/dist/dts/genesis/types.d.ts.map +1 -1
  24. package/dist/dts/genesis/vendor-follower.d.ts +86 -0
  25. package/dist/dts/genesis/vendor-follower.d.ts.map +1 -0
  26. package/dist/dts/genesis/vendor-pick.d.ts +36 -0
  27. package/dist/dts/genesis/vendor-pick.d.ts.map +1 -0
  28. package/dist/dts/index.d.ts +1 -0
  29. package/dist/dts/index.d.ts.map +1 -1
  30. package/dist/dts/main/budget-controller.d.ts +6 -0
  31. package/dist/dts/main/budget-controller.d.ts.map +1 -1
  32. package/dist/dts/main/main.d.ts +30 -0
  33. package/dist/dts/main/main.d.ts.map +1 -1
  34. package/dist/dts/main/vendor-picker-controller.d.ts +89 -0
  35. package/dist/dts/main/vendor-picker-controller.d.ts.map +1 -0
  36. package/dist/dts/provider/ai-provider-switcher.d.ts +22 -1
  37. package/dist/dts/provider/ai-provider-switcher.d.ts.map +1 -1
  38. package/dist/dts/provider/tiered-provider-switcher.d.ts +39 -2
  39. package/dist/dts/provider/tiered-provider-switcher.d.ts.map +1 -1
  40. package/dist/esm/chat-driver-node.js +1 -1
  41. package/dist/esm/components/chat-driver/chat-driver.js +3 -2
  42. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +1 -0
  43. package/dist/esm/components/settings-modal/settings-modal.js +4 -1
  44. package/dist/esm/components/settings-modal/settings-modal.styles.js +59 -0
  45. package/dist/esm/components/settings-modal/settings-modal.template.js +54 -1
  46. package/dist/esm/genesis/config.js +1 -1
  47. package/dist/esm/genesis/consumes.js +1 -1
  48. package/dist/esm/genesis/register-genesis-assistant.js +72 -7
  49. package/dist/esm/genesis/vendor-follower.js +149 -0
  50. package/dist/esm/genesis/vendor-pick.js +67 -0
  51. package/dist/esm/main/budget-controller.js +11 -9
  52. package/dist/esm/main/main.js +57 -0
  53. package/dist/esm/main/vendor-picker-controller.js +141 -0
  54. package/dist/esm/provider/tiered-provider-switcher.js +54 -1
  55. package/dist/genesis-consumes.cjs +1 -1
  56. package/dist/genesis-consumes.cjs.map +2 -2
  57. package/dist/genesis-consumes.mjs +1 -1
  58. package/dist/genesis-consumes.mjs.map +2 -2
  59. package/docs/genesis.md +37 -3
  60. package/package.json +17 -17
  61. package/scripts/smoke-genesis-consumes-node.mjs +1 -1
@@ -1,11 +1,15 @@
1
1
  import { __awaiter } from "tslib";
2
- import { isAIFeatureEnabled, resolveAITiers } from '@genesislcap/foundation-ai';
2
+ import { AI_TIER_VENDORS, isAIFeatureEnabled, resolveAITiers, } from '@genesislcap/foundation-ai';
3
+ import { User } from '@genesislcap/foundation-comms';
3
4
  import { PUBLIC_PATH } from '@genesislcap/foundation-utils';
4
5
  import { DI } from '@genesislcap/web-core';
6
+ import { agenticActivityBus } from '../channel/ai-activity-bus';
5
7
  import { registerTieredAIProviders, } from '../provider/tiered-provider-switcher';
6
8
  import { logger } from '../utils/logger';
7
9
  import { toolNameOf, validateGenesisAiConfig } from './config';
8
10
  import { createGenesisResourceTools } from './resource-tools';
11
+ import { followServerVendor } from './vendor-follower';
12
+ import { vendorPickStore } from './vendor-pick';
9
13
  import { createGenesisWriteTools, mintFeedbackKey } from './write-tools';
10
14
  /**
11
15
  * The name of the agent {@link registerGenesisAssistant} builds.
@@ -137,6 +141,38 @@ export function defaultEndpointBase(publicPath = PUBLIC_PATH) {
137
141
  * what lets a test set it.
138
142
  */
139
143
  const buildChatBase = () => typeof GENX_AI_CHAT_BASE !== 'undefined' ? String(GENX_AI_CHAT_BASE).trim() : '';
144
+ /**
145
+ * The base the chat posts to as `<base>/<vendor>/chat`, and asks `<base>/vendor` at: the app's
146
+ * own `endpointBase`, else {@link defaultEndpointBase}. Trailing slashes trimmed.
147
+ *
148
+ * @internal
149
+ */
150
+ export function chatEndpointBase(options = {}) {
151
+ var _a;
152
+ return ((_a = options.endpointBase) !== null && _a !== void 0 ? _a : defaultEndpointBase()).replace(/\/+$/, '');
153
+ }
154
+ /**
155
+ * Whether the app is running in Genesis Create's preview: a build-time `GENX_AI_CHAT_BASE`, which
156
+ * only the preview sets, that the app has not replaced with an `endpointBase` of its own. Create
157
+ * chooses the vendor there, so the assistant's settings show it read-only.
158
+ *
159
+ * @internal
160
+ */
161
+ export function inCreatePreview(options = {}) {
162
+ const ownBase = options.endpointBase !== undefined && options.endpointBase !== null;
163
+ return !ownBase && buildChatBase() !== '';
164
+ }
165
+ /**
166
+ * The vendors the chat offers before its AI proxy has said which it can serve, and for good when
167
+ * the proxy cannot say: the app's own `vendors`, else the configured vendor alone. Exactly what
168
+ * the bridge registered before it asked the proxy at all.
169
+ *
170
+ * @internal
171
+ */
172
+ export function startingVendors(config, options = {}) {
173
+ var _a, _b;
174
+ return (_a = options.vendors) !== null && _a !== void 0 ? _a : [(_b = config.vendor) !== null && _b !== void 0 ? _b : 'gemini'];
175
+ }
140
176
  /**
141
177
  * The provider options {@link registerGenesisAssistant} registers — split out so the choice of
142
178
  * vendor, tier and endpoint can be checked without building providers.
@@ -149,13 +185,20 @@ const buildChatBase = () => typeof GENX_AI_CHAT_BASE !== 'undefined' ? String(GE
149
185
  * @internal
150
186
  */
151
187
  export function genesisProviderOptions(config, options = {}) {
152
- var _a, _b, _c, _d;
188
+ var _a, _b, _c;
153
189
  const vendor = (_a = config.vendor) !== null && _a !== void 0 ? _a : 'gemini';
154
- const base = ((_b = options.endpointBase) !== null && _b !== void 0 ? _b : defaultEndpointBase()).replace(/\/+$/, '');
190
+ const base = chatEndpointBase(options);
155
191
  return {
156
192
  initialVendor: vendor,
157
- vendors: (_c = options.vendors) !== null && _c !== void 0 ? _c : [vendor],
158
- defaultTier: (_d = config.tier) !== null && _d !== void 0 ? _d : 'high',
193
+ // In Create's preview the user picks the vendor in Create; anywhere else, in the assistant's
194
+ // settings, which show a card per vendor once the proxy offers two or more.
195
+ vendorChoice: inCreatePreview(options)
196
+ ? { kind: 'elsewhere', where: 'Genesis Create' }
197
+ : { kind: 'in-app' },
198
+ // Every vendor the chat might be told it can use. registerGenesisAssistant narrows to
199
+ // startingVendors straight away, and the proxy's answer chooses among these.
200
+ vendors: (_b = options.vendors) !== null && _b !== void 0 ? _b : AI_TIER_VENDORS,
201
+ defaultTier: (_c = config.tier) !== null && _c !== void 0 ? _c : 'high',
159
202
  tiers: resolveAITiers(),
160
203
  serverEndpoint: (v) => `${base}/${v}/chat`,
161
204
  };
@@ -184,7 +227,7 @@ export function genesisProviderOptions(config, options = {}) {
184
227
  * @beta
185
228
  */
186
229
  export function registerGenesisAssistant(options) {
187
- var _a, _b, _c, _d;
230
+ var _a, _b, _c, _d, _e, _f;
188
231
  /**
189
232
  * `off` is a choice (AI switched off in the build or the config), `fault` is anything else.
190
233
  * Named at every call rather than defaulted: which sentence the user reads, and whether the
@@ -302,12 +345,34 @@ export function registerGenesisAssistant(options) {
302
345
  return blocked('fault', 'rowSources must be an object of event name to request resource name.');
303
346
  }
304
347
  let switcher;
348
+ const providerOptions = genesisProviderOptions(config, options);
349
+ const container = (_d = options.container) !== null && _d !== void 0 ? _d : DI.getOrCreateDOMContainer();
350
+ const base = chatEndpointBase(options);
351
+ // A pick made in the settings, remembered per user and app. Only where the user picks: in
352
+ // Create's preview, Create does, and the proxy's answer is followed as it is.
353
+ const picks = ((_e = providerOptions.vendorChoice) === null || _e === void 0 ? void 0 : _e.kind) === 'in-app'
354
+ ? vendorPickStore({ base, user: () => { var _a; return (_a = container.get(User)) === null || _a === void 0 ? void 0 : _a.userName; } })
355
+ : undefined;
305
356
  try {
306
- switcher = registerTieredAIProviders((_d = options.container) !== null && _d !== void 0 ? _d : DI.getOrCreateDOMContainer(), genesisProviderOptions(config, options));
357
+ switcher = registerTieredAIProviders(container, Object.assign(Object.assign({}, providerOptions), { onSwitch: picks ? (vendor) => picks.write(vendor) : undefined }));
307
358
  }
308
359
  catch (error) {
309
360
  return blocked('fault', `The AI providers could not be registered: ${error.message}`);
310
361
  }
362
+ // Starts as the bridge always has, on the configured vendor alone (or the app's own list), and
363
+ // stays there unless the proxy answers which vendors it can serve: in Create's preview, the one
364
+ // the user selected there; in an exported app, the ones whose key its server holds. Still
365
+ // synchronous, before the element can resolve a provider. Lives as long as the page does.
366
+ const starting = startingVendors(config, options);
367
+ switcher.setAvailableVendors(starting);
368
+ followServerVendor({
369
+ base,
370
+ switcher,
371
+ vendors: (_f = providerOptions.vendors) !== null && _f !== void 0 ? _f : AI_TIER_VENDORS,
372
+ fallback: { vendors: starting, vendor: providerOptions.initialVendor },
373
+ picked: picks ? () => picks.read() : undefined,
374
+ bus: agenticActivityBus,
375
+ });
311
376
  // The last check that can block is behind us.
312
377
  for (const line of leftOut)
313
378
  logger.warn(`Genesis assistant: ${line}`);
@@ -0,0 +1,149 @@
1
+ import { __awaiter } from "tslib";
2
+ import { logger } from '../utils/logger';
3
+ /** The answer, when it has the agreed shape; `undefined` for anything else. */
4
+ const readAnswer = (body) => {
5
+ if (!body || typeof body !== 'object')
6
+ return undefined;
7
+ const { vendor, offeredVendors } = body;
8
+ if (typeof vendor !== 'string' || !Array.isArray(offeredVendors))
9
+ return undefined;
10
+ if (!offeredVendors.every((v) => typeof v === 'string'))
11
+ return undefined;
12
+ return { vendor, offeredVendors: offeredVendors };
13
+ };
14
+ /**
15
+ * Keep a Genesis app's chat on the vendor its AI proxy names, among the vendors it can serve.
16
+ *
17
+ * @remarks
18
+ * The app is generated with one vendor in its config, but which vendors can actually answer is
19
+ * known only at run time. In Genesis Create's preview the user picks the vendor in Create and can
20
+ * change it at any time; a regenerate or a reload to pick it up would be a needless cost, and
21
+ * while the config's vendor is out of budget the preview chat would otherwise be dead. An exported
22
+ * app's server may hold a key for a vendor other than the config's, or for several. So the bridge
23
+ * asks: at registration, when the window regains focus or the tab becomes visible (which is how
24
+ * the user comes back from Create's vendor control), and after every turn.
25
+ *
26
+ * A vendor the user picked in the app is kept for as long as the proxy still offers it; the
27
+ * answer's `vendor` is taken only when it does not.
28
+ *
29
+ * Never mid-turn: a turn that started on one vendor finishes on it. The follower counts the tool
30
+ * loops running, because a sub-agent's driver publishes its own loop start and end on its
31
+ * parent's bus; only when the last one ends is the turn over. An answer that lands while a
32
+ * turn runs is dropped, and the one asked at the turn's end replaces it. Only the latest answer
33
+ * counts, so a slow one cannot undo a newer one.
34
+ *
35
+ * An answer offering no vendor at all (no key is set) puts the chat back on what it started on,
36
+ * so the proxy's own NO_API_KEY refusal reaches the user. Anything else but the agreed answer
37
+ * changes nothing: a failed request or an error status (404 from a proxy too old to answer, 403
38
+ * for a user without the AI right), a body of another shape, offered vendors this app does not
39
+ * know, or a vendor that is not offered. The app then stays on whatever
40
+ * it was on, which before the first good answer is its config's vendor alone. All of it is logged
41
+ * at debug level: an older proxy is an expected case, not a fault.
42
+ *
43
+ * @internal
44
+ */
45
+ export function followServerVendor(options) {
46
+ var _a, _b, _c;
47
+ const { base, switcher, vendors, bus, fallback, picked } = options;
48
+ const doFetch = (_a = options.fetch) !== null && _a !== void 0 ? _a : (typeof fetch === 'function' ? fetch : undefined);
49
+ const target = (_b = options.target) !== null && _b !== void 0 ? _b : (typeof window !== 'undefined' ? window : undefined);
50
+ const url = `${base}/vendor`;
51
+ let asked = 0;
52
+ // Loops running, not a flag: a sub-agent's driver shares its parent's bus and publishes its own
53
+ // start and end, so one finishing must not read as the parent's turn ending.
54
+ let loopsRunning = 0;
55
+ let disposed = false;
56
+ const apply = (answer) => {
57
+ // No key set anywhere: back to what the chat started on, whose requests the proxy refuses
58
+ // with NO_API_KEY, which the chat shows. Its `vendor` (the generated default) is not used:
59
+ // the chat already has that one.
60
+ if (!answer.offeredVendors.length) {
61
+ logger.debug('Genesis assistant: the AI proxy offers no vendor; using the configured one.');
62
+ switcher.setAvailableVendors(fallback.vendors, fallback.vendor);
63
+ return;
64
+ }
65
+ const offered = answer.offeredVendors.filter((v) => vendors.includes(v));
66
+ if (!offered.length || !offered.includes(answer.vendor)) {
67
+ logger.debug(`Genesis assistant: the AI proxy offered ${JSON.stringify(answer)}; keeping the ` +
68
+ 'current vendor.');
69
+ return;
70
+ }
71
+ // The user's own pick, while it is still offered: a refresh on focus must not undo it.
72
+ const pick = picked === null || picked === void 0 ? void 0 : picked();
73
+ switcher.setAvailableVendors(offered, pick && offered.includes(pick) ? pick : answer.vendor);
74
+ };
75
+ const refresh = () => __awaiter(this, void 0, void 0, function* () {
76
+ if (disposed || !doFetch)
77
+ return;
78
+ asked += 1;
79
+ const mine = asked;
80
+ let answer;
81
+ try {
82
+ const response = yield doFetch(url, {
83
+ method: 'GET',
84
+ credentials: 'include',
85
+ // The exported app's proxy sends no Cache-Control (one there grows its router's cache),
86
+ // and a cached answer would pin the chat to the vendors offered when it was cached.
87
+ cache: 'no-store',
88
+ headers: { Accept: 'application/json' },
89
+ });
90
+ if (!response.ok) {
91
+ logger.debug(`Genesis assistant: ${url} answered ${response.status}; keeping the vendor.`);
92
+ return;
93
+ }
94
+ answer = readAnswer(yield response.json());
95
+ }
96
+ catch (error) {
97
+ logger.debug(`Genesis assistant: ${url} failed; keeping the vendor.`, error);
98
+ return;
99
+ }
100
+ if (disposed || mine !== asked || loopsRunning > 0)
101
+ return;
102
+ if (!answer) {
103
+ logger.debug(`Genesis assistant: ${url} answered an unexpected shape; keeping the vendor.`);
104
+ return;
105
+ }
106
+ // Outside the request's try, yet still not allowed to reject: every trigger fires this and
107
+ // forgets it, and a switcher subscriber (which may be the app's own code) can throw.
108
+ try {
109
+ apply(answer);
110
+ }
111
+ catch (error) {
112
+ logger.debug("Genesis assistant: the AI proxy's vendor could not be applied.", error);
113
+ }
114
+ });
115
+ const ask = () => {
116
+ void refresh();
117
+ };
118
+ const onVisible = () => {
119
+ var _a;
120
+ if (((_a = target === null || target === void 0 ? void 0 : target.document) === null || _a === void 0 ? void 0 : _a.visibilityState) === 'visible')
121
+ ask();
122
+ };
123
+ const unsubscribe = [
124
+ bus.subscribe('tool-loop-start', () => {
125
+ loopsRunning += 1;
126
+ }),
127
+ bus.subscribe('tool-loop-end', () => {
128
+ // Never below zero: an end whose start came before the follower subscribed.
129
+ loopsRunning = Math.max(0, loopsRunning - 1);
130
+ // Ask only when the last loop ends, which is the turn's: a sub-agent's end is mid-turn.
131
+ if (loopsRunning === 0)
132
+ ask();
133
+ }),
134
+ ];
135
+ target === null || target === void 0 ? void 0 : target.addEventListener('focus', ask);
136
+ (_c = target === null || target === void 0 ? void 0 : target.document) === null || _c === void 0 ? void 0 : _c.addEventListener('visibilitychange', onVisible);
137
+ ask();
138
+ return {
139
+ refresh,
140
+ dispose: () => {
141
+ var _a;
142
+ disposed = true;
143
+ for (const off of unsubscribe)
144
+ off();
145
+ target === null || target === void 0 ? void 0 : target.removeEventListener('focus', ask);
146
+ (_a = target === null || target === void 0 ? void 0 : target.document) === null || _a === void 0 ? void 0 : _a.removeEventListener('visibilitychange', onVisible);
147
+ },
148
+ };
149
+ }
@@ -0,0 +1,67 @@
1
+ const defaultStorage = () => typeof localStorage === 'undefined' ? undefined : localStorage;
2
+ /**
3
+ * Remember a user's vendor pick per user and app, in browser storage.
4
+ *
5
+ * @remarks
6
+ * Storage is a convenience, never a requirement: every read and write is guarded, and a copy kept
7
+ * in memory answers for the page's life when storage is missing, full, or refuses (a private
8
+ * window, blocked site data). That copy is read first, so a pick whose write failed still beats an
9
+ * older one left in storage; the older one is also removed, so a reload does not bring it back.
10
+ * The user is read at each call rather than once, so a sign-in after the assistant registered
11
+ * still keys the pick to the right person.
12
+ *
13
+ * Per user and app rather than per chat session: the vendor switcher, and the provider registry
14
+ * it drives, is one per page, so every session on the page runs on the one vendor.
15
+ *
16
+ * @internal
17
+ */
18
+ export function vendorPickStore(options) {
19
+ var _a;
20
+ const storage = (_a = options.storage) !== null && _a !== void 0 ? _a : defaultStorage;
21
+ const memory = new Map();
22
+ const key = () => {
23
+ let user;
24
+ try {
25
+ user = options.user();
26
+ }
27
+ catch (_a) {
28
+ user = undefined;
29
+ }
30
+ return `genesis-ai-assistant:vendor:${user !== null && user !== void 0 ? user : ''}@${options.base}`;
31
+ };
32
+ return {
33
+ read() {
34
+ var _a;
35
+ const k = key();
36
+ // This page's own pick first: it is the newest, and the one storage may have failed to take.
37
+ const mine = memory.get(k);
38
+ if (mine)
39
+ return mine;
40
+ try {
41
+ return ((_a = storage()) === null || _a === void 0 ? void 0 : _a.getItem(k)) || undefined;
42
+ }
43
+ catch (_b) {
44
+ // Storage unavailable: nothing remembered from an earlier page.
45
+ return undefined;
46
+ }
47
+ },
48
+ write(vendor) {
49
+ var _a, _b;
50
+ const k = key();
51
+ memory.set(k, vendor);
52
+ try {
53
+ (_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(k, vendor);
54
+ }
55
+ catch (_c) {
56
+ // Storage unavailable or full: the in-memory copy holds the pick for this page. A pick it
57
+ // still holds from before is stale now, so drop it rather than restore it on a reload.
58
+ try {
59
+ (_b = storage()) === null || _b === void 0 ? void 0 : _b.removeItem(k);
60
+ }
61
+ catch (_d) {
62
+ // Nothing more to do: the in-memory copy still wins for this page.
63
+ }
64
+ }
65
+ },
66
+ };
67
+ }
@@ -63,7 +63,7 @@ function vendorDisplayName(vendor) {
63
63
  return (_a = VENDOR_LABELS[vendor]) !== null && _a !== void 0 ? _a : vendor;
64
64
  }
65
65
  /**
66
- * `a`, `a and b`, `a, b and c`.
66
+ * `a`, `a or b`, `a, b or c`: the vendors the user may switch to, of which they pick one.
67
67
  *
68
68
  * The general joiner is kept rather than hardcoded to a pair because the list
69
69
  * is `BUDGETED_VENDORS`-shaped, and that list is a cross-repo contract owned by
@@ -76,18 +76,19 @@ function vendorDisplayName(vendor) {
76
76
  * excluded from both.
77
77
  */
78
78
  function formatVendorList(vendors) {
79
- return joinList(vendors.map(vendorDisplayName));
79
+ return joinList(vendors.map(vendorDisplayName), 'or');
80
80
  }
81
81
  /**
82
82
  * `"A"`, `"A and B"`, `"A, B and C"` — over already-rendered labels, so a caller
83
83
  * can annotate each name (the multi-vendor banner appends each vendor's figures)
84
- * without duplicating the joining rules.
84
+ * without duplicating the joining rules. `'or'` for a choice: "Switch to Anthropic
85
+ * and OpenAI" read as though the user should switch to both.
85
86
  */
86
- function joinList(names) {
87
+ function joinList(names, conjunction = 'and') {
87
88
  var _a;
88
89
  if (names.length <= 1)
89
90
  return (_a = names[0]) !== null && _a !== void 0 ? _a : '';
90
- return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;
91
+ return `${names.slice(0, -1).join(', ')} ${conjunction} ${names[names.length - 1]}`;
91
92
  }
92
93
  /**
93
94
  * Whole-number percentage of a budget consumed, for the meter (GENC-1464).
@@ -783,7 +784,7 @@ export class BudgetController {
783
784
  * its vendors watched all of it vanish the moment a second one walled.
784
785
  */
785
786
  get effectiveBlockedReason() {
786
- var _a, _b;
787
+ var _a, _b, _c, _d;
787
788
  if (this.blockedReason)
788
789
  return this.blockedReason;
789
790
  // A block that is not a budget wall, with no reason from the host, says so neutrally rather than
@@ -795,13 +796,14 @@ export class BudgetController {
795
796
  if (walled.length === 0)
796
797
  return DEFAULT_BUDGET_EXHAUSTED_MESSAGE;
797
798
  const free = this.reachableVendors.filter((v) => !walled.includes(v));
799
+ const place = (_b = (_a = this.deps).vendorSwitchPlace) === null || _b === void 0 ? void 0 : _b.call(_a);
798
800
  const action = free.length
799
- ? `Switch to ${formatVendorList(free)} to keep going.`
801
+ ? `Switch to ${formatVendorList(free)}${place ? ` ${place}` : ''} to keep going.`
800
802
  : walled.length > 1
801
803
  ? RAISE_LIMITS_ACTION
802
804
  : RAISE_LIMIT_ACTION;
803
- const reasons = (_a = this.slice) === null || _a === void 0 ? void 0 : _a.blockedVendorReasons;
804
- const budgets = (_b = this.slice) === null || _b === void 0 ? void 0 : _b.vendorBudgets;
805
+ const reasons = (_c = this.slice) === null || _c === void 0 ? void 0 : _c.blockedVendorReasons;
806
+ const budgets = (_d = this.slice) === null || _d === void 0 ? void 0 : _d.vendorBudgets;
805
807
  // The wall's own figures, read from the entry the METER renders, so the two
806
808
  // cannot state different dollars for the same vendor. A vendor with no entry
807
809
  // (a swept wall — the proxy's word, no figures of its own) contributes a bare
@@ -48,6 +48,7 @@ import { AiWavesIndicator } from '../components/waves-indicator';
48
48
  import { agentNotificationPermission, asAgentNotificationLevel, belongsToSession, chooseAgentNotificationLevel, effectiveNotificationLevel, levelOffered, notificationPermissionHint, notificationsOffered, watchAgentNotificationPermission, } from '../notifications/agent-notifications';
49
49
  import { AgentNotifier } from '../notifications/agent-notifier';
50
50
  import { addNotificationSettingsHost, announceNotificationSettings, } from '../notifications/notification-settings';
51
+ import { AIProviderSwitcher } from '../provider/ai-provider-switcher';
51
52
  import { AssistantAppSettingsProvider, } from '../provider/assistant-app-settings';
52
53
  import { recordMetaEvent, clearSession as clearMetaSession, DEBUG_LOG_README, } from '../state/debug-event-log';
53
54
  import { getOrCreateDriver, getDriver, getDriverAgentsKey, deleteDriver, } from '../state/driver-registry';
@@ -75,6 +76,7 @@ import { stripAgentHandlers } from '../utils/strip-agent-handlers';
75
76
  import { emptyUsage, sumUsage, totalTokens } from '../utils/sum-usage';
76
77
  import { AttachmentController } from './attachment-controller';
77
78
  import { BudgetController } from './budget-controller';
79
+ import { VendorPickerController, } from './vendor-picker-controller';
78
80
  import { ComposerMenuController } from './composer-menu-controller';
79
81
  import { ComposerResizeController } from './composer-resize-controller';
80
82
  import { ContextGateController } from './context-gate-controller';
@@ -293,6 +295,16 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
293
295
  providerStatuses: () => this.providerStatuses,
294
296
  providerRegistry: () => this.providerRegistry,
295
297
  chatConfig: () => this.chatConfig,
298
+ vendorSwitchPlace: () => this.vendorPicker.switchPlace,
299
+ });
300
+ /**
301
+ * The vendor control in the settings' AI model section, shown only when the registered
302
+ * switcher asks for one through its `vendorChoice`.
303
+ */
304
+ this.vendorPicker = new VendorPickerController({
305
+ switcher: () => this.providerSwitcher,
306
+ computing: () => this.busy && !this.hasActivePendingInteraction,
307
+ hostControl: () => this.settings.modelSlotted.length > 0,
296
308
  });
297
309
  /**
298
310
  * The settings modal (`docs/code-health.md` §3). Reaches the two design-system
@@ -304,6 +316,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
304
316
  contextTokens: () => this.contextTokens,
305
317
  contextLimit: () => this.contextLimit,
306
318
  budgetUsageVisible: () => this.budget.settingsUsageVisible,
319
+ vendorPickerVisible: () => this.vendorPicker.visible,
307
320
  costConfig: () => this.costLedger.config,
308
321
  costHistoryLength: () => this.costLedger.history.length,
309
322
  liveCostSessionTitle: () => this.costLedger.liveTitle,
@@ -2217,6 +2230,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
2217
2230
  maxTurnSnapshots: agent.maxTurnSnapshots,
2218
2231
  activityBus: agenticActivityBus,
2219
2232
  budgetExhaustedMessage: this.transcriptBudgetExhaustedMessage,
2233
+ vendorSwitchPlace: this.transcriptVendorSwitchPlace,
2220
2234
  aiServiceErrorMessages: this.aiServiceErrorMessages,
2221
2235
  });
2222
2236
  // The autopilot is installed outermost, and only when some agent declares one (GENC-1660).
@@ -2238,6 +2252,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
2238
2252
  sessionKey: (_d = this.getStateKey()) !== null && _d !== void 0 ? _d : '',
2239
2253
  activityBus: agenticActivityBus,
2240
2254
  budgetExhaustedMessage: this.transcriptBudgetExhaustedMessage,
2255
+ vendorSwitchPlace: this.transcriptVendorSwitchPlace,
2241
2256
  aiServiceErrorMessages: this.aiServiceErrorMessages,
2242
2257
  });
2243
2258
  }
@@ -2654,8 +2669,11 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
2654
2669
  this.unsubProviderRegistry = this.providerRegistry.subscribe(() => {
2655
2670
  void this.resolveContextLimit();
2656
2671
  void this.loadProviderStatuses();
2672
+ // The switcher says when its vendor changes, not when its list does; both rebuild this.
2673
+ this.vendorPicker.refresh();
2657
2674
  });
2658
2675
  }
2676
+ this.vendorPicker.wire();
2659
2677
  this.settings.wireAppSettingsProvider();
2660
2678
  this.wireNotifications();
2661
2679
  // Latch the backend block off the activity bus (GENC-1464). This is the primary
@@ -2801,6 +2819,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
2801
2819
  this._unwireNotifications = undefined;
2802
2820
  (_d = this.unsubProviderRegistry) === null || _d === void 0 ? void 0 : _d.call(this);
2803
2821
  this.unsubProviderRegistry = undefined;
2822
+ this.vendorPicker.unwire();
2804
2823
  this.settings.unwireAppSettingsProvider();
2805
2824
  (_e = this._executionCompletionUnsub) === null || _e === void 0 ? void 0 : _e.call(this);
2806
2825
  this._executionCompletionUnsub = undefined;
@@ -3651,6 +3670,41 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
3651
3670
  get settingsModelSectionVisible() {
3652
3671
  return this.settings.modelSectionVisible;
3653
3672
  }
3673
+ /**
3674
+ * The settings' vendor cards, one per vendor, while the switcher's `vendorChoice` is `in-app`
3675
+ * and it has two or more vendors; otherwise none.
3676
+ *
3677
+ * @internal
3678
+ */
3679
+ get settingsVendorOptions() {
3680
+ return this.vendorPicker.options;
3681
+ }
3682
+ /** @internal */
3683
+ get settingsVendorPickerVisible() {
3684
+ return this.vendorPicker.pickerVisible;
3685
+ }
3686
+ /** Whether the cards are disabled: a turn is computing. @internal */
3687
+ get settingsVendorPickerDisabled() {
3688
+ return this.vendorPicker.disabled;
3689
+ }
3690
+ /** The active vendor read-only, when the switcher says it is chosen elsewhere. @internal */
3691
+ get settingsVendorSelectedElsewhere() {
3692
+ return this.vendorPicker.selectedElsewhere;
3693
+ }
3694
+ /** A vendor card was picked. @internal */
3695
+ selectSettingsVendor(vendor) {
3696
+ this.vendorPicker.select(vendor);
3697
+ }
3698
+ /**
3699
+ * Where the transcript's budget bubble tells the user to switch vendor, when that is outside
3700
+ * the app (Genesis Create's preview). The driver is built once, and this does not change after
3701
+ * registration; the default, "in Settings", is the in-app picker's.
3702
+ */
3703
+ get transcriptVendorSwitchPlace() {
3704
+ var _a;
3705
+ const choice = (_a = this.providerSwitcher) === null || _a === void 0 ? void 0 : _a.vendorChoice;
3706
+ return (choice === null || choice === void 0 ? void 0 : choice.kind) === 'elsewhere' ? `in ${choice.where}` : undefined;
3707
+ }
3654
3708
  /** Built-in context window indicator (generic platform concern). */
3655
3709
  get settingsContextUsageVisible() {
3656
3710
  return this.settings.contextUsageVisible;
@@ -5037,6 +5091,9 @@ FoundationAiAssistant.MS_PER_SECOND = 1000;
5037
5091
  __decorate([
5038
5092
  AIProviderRegistry
5039
5093
  ], FoundationAiAssistant.prototype, "providerRegistry", void 0);
5094
+ __decorate([
5095
+ AIProviderSwitcher
5096
+ ], FoundationAiAssistant.prototype, "providerSwitcher", void 0);
5040
5097
  __decorate([
5041
5098
  AssistantAppSettingsProvider
5042
5099
  ], FoundationAiAssistant.prototype, "appSettingsProvider", void 0);
@@ -0,0 +1,141 @@
1
+ import { __decorate } from "tslib";
2
+ import { VENDOR_LABELS } from '@genesislcap/foundation-ai';
3
+ import { observable, volatile } from '@genesislcap/web-core';
4
+ /** What a vendor is called in the settings: the platform's label, else the vendor id. */
5
+ export const vendorLabel = (vendor) => { var _a; return (_a = VENDOR_LABELS[vendor]) !== null && _a !== void 0 ? _a : vendor; };
6
+ /**
7
+ * The vendor control in the settings' AI model section.
8
+ *
9
+ * @remarks
10
+ * It is the fallback content of the `settings-model` slot, so a host that slots its own control
11
+ * there (Genesis Create) keeps only its own. And it shows only what the switcher asks for through
12
+ * its `vendorChoice`, so a host with a control elsewhere (the showcase's header button) gets none
13
+ * either. With `in-app`, a card per vendor while there are two or more; with `elsewhere`, the
14
+ * active vendor read-only, naming where it is chosen.
15
+ *
16
+ * The switcher announces a vendor change but not a change to its list of vendors, so the host
17
+ * calls {@link VendorPickerController.refresh} whenever the provider registry changes too: every
18
+ * change to either rebuilds the registry.
19
+ *
20
+ * @internal
21
+ */
22
+ export class VendorPickerController {
23
+ constructor(deps) {
24
+ this.deps = deps;
25
+ /** Bumped on every switcher or registry change, so the getters below re-evaluate. */
26
+ this.revision = 0;
27
+ }
28
+ /** Follow the switcher's vendor. Call on connect; balanced by {@link VendorPickerController.unwire}. */
29
+ wire() {
30
+ var _a;
31
+ this.unwire();
32
+ this.unsubscribe = (_a = this.deps.switcher()) === null || _a === void 0 ? void 0 : _a.subscribe(() => this.refresh());
33
+ this.refresh();
34
+ }
35
+ unwire() {
36
+ var _a;
37
+ (_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
38
+ this.unsubscribe = undefined;
39
+ }
40
+ refresh() {
41
+ this.revision += 1;
42
+ }
43
+ get choice() {
44
+ var _a;
45
+ // Read for the dependency: the switcher itself is not observable.
46
+ void this.revision;
47
+ return (_a = this.deps.switcher()) === null || _a === void 0 ? void 0 : _a.vendorChoice;
48
+ }
49
+ /** An `in-app` choice with two or more vendors: something to pick, wherever the control is. */
50
+ get choosable() {
51
+ var _a, _b, _c;
52
+ return ((_a = this.choice) === null || _a === void 0 ? void 0 : _a.kind) === 'in-app' && ((_c = (_b = this.deps.switcher()) === null || _b === void 0 ? void 0 : _b.vendors.length) !== null && _c !== void 0 ? _c : 0) > 1;
53
+ }
54
+ /** The host's own control in `settings-model` replaces this one. */
55
+ get replaced() {
56
+ var _a, _b, _c;
57
+ return (_c = (_b = (_a = this.deps).hostControl) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false;
58
+ }
59
+ /** Cards to pick from: something to pick, and no control of the host's own in the slot. */
60
+ get pickerVisible() {
61
+ return this.choosable && !this.replaced;
62
+ }
63
+ get options() {
64
+ if (!this.pickerVisible)
65
+ return [];
66
+ const switcher = this.deps.switcher();
67
+ if (!switcher)
68
+ return [];
69
+ return switcher.vendors.map((vendor) => ({
70
+ vendor,
71
+ label: vendorLabel(vendor),
72
+ checked: vendor === switcher.vendor,
73
+ }));
74
+ }
75
+ /** The active vendor read-only, when it is chosen outside the app. */
76
+ get selectedElsewhere() {
77
+ var _a;
78
+ const choice = this.choice;
79
+ const vendor = (_a = this.deps.switcher()) === null || _a === void 0 ? void 0 : _a.vendor;
80
+ if ((choice === null || choice === void 0 ? void 0 : choice.kind) !== 'elsewhere' || !vendor || this.replaced)
81
+ return undefined;
82
+ return { label: vendorLabel(vendor), where: choice.where };
83
+ }
84
+ /** Whether the section has a vendor block to show at all. */
85
+ get visible() {
86
+ return this.pickerVisible || this.selectedElsewhere !== undefined;
87
+ }
88
+ get disabled() {
89
+ return this.deps.computing();
90
+ }
91
+ /**
92
+ * Where the user switches vendor, as a phrase completing "Switch to Gemini …": `'in Settings'`
93
+ * when the user picks there (these cards, or a control the host slotted in their place),
94
+ * `'in <where>'` when the vendor is chosen elsewhere, otherwise `undefined` (the copy then
95
+ * names no place, as it always has).
96
+ */
97
+ get switchPlace() {
98
+ if (this.choosable)
99
+ return 'in Settings';
100
+ const choice = this.choice;
101
+ return (choice === null || choice === void 0 ? void 0 : choice.kind) === 'elsewhere' ? `in ${choice.where}` : undefined;
102
+ }
103
+ /** A card was picked. Ignored while a turn computes or when the cards are not showing. */
104
+ select(vendor) {
105
+ var _a;
106
+ if (this.disabled || !this.pickerVisible) {
107
+ // Put a radio the user just checked back on the active vendor.
108
+ this.refresh();
109
+ return;
110
+ }
111
+ (_a = this.deps.switcher()) === null || _a === void 0 ? void 0 : _a.switchTo(vendor);
112
+ this.refresh();
113
+ }
114
+ }
115
+ __decorate([
116
+ observable
117
+ ], VendorPickerController.prototype, "revision", void 0);
118
+ __decorate([
119
+ volatile
120
+ ], VendorPickerController.prototype, "choice", null);
121
+ __decorate([
122
+ volatile
123
+ ], VendorPickerController.prototype, "choosable", null);
124
+ __decorate([
125
+ volatile
126
+ ], VendorPickerController.prototype, "pickerVisible", null);
127
+ __decorate([
128
+ volatile
129
+ ], VendorPickerController.prototype, "options", null);
130
+ __decorate([
131
+ volatile
132
+ ], VendorPickerController.prototype, "selectedElsewhere", null);
133
+ __decorate([
134
+ volatile
135
+ ], VendorPickerController.prototype, "visible", null);
136
+ __decorate([
137
+ volatile
138
+ ], VendorPickerController.prototype, "disabled", null);
139
+ __decorate([
140
+ volatile
141
+ ], VendorPickerController.prototype, "switchPlace", null);