@genesislcap/ai-assistant 15.108.0 → 15.109.1
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/dist/ai-assistant.api.json +410 -4
- package/dist/ai-assistant.d.ts +121 -2
- package/dist/chat-driver.cjs +33 -15
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +33 -15
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +891 -690
- package/dist/dts/components/chat-driver/chat-driver.d.ts +9 -0
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +2 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.d.ts +2 -0
- package/dist/dts/components/settings-modal/settings-modal.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.styles.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.template.d.ts +1 -0
- package/dist/dts/components/settings-modal/settings-modal.template.d.ts.map +1 -1
- package/dist/dts/genesis/register-genesis-assistant.d.ts +24 -0
- package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
- package/dist/dts/genesis/types.d.ts +8 -2
- package/dist/dts/genesis/types.d.ts.map +1 -1
- package/dist/dts/genesis/vendor-follower.d.ts +86 -0
- package/dist/dts/genesis/vendor-follower.d.ts.map +1 -0
- package/dist/dts/genesis/vendor-pick.d.ts +36 -0
- package/dist/dts/genesis/vendor-pick.d.ts.map +1 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/budget-controller.d.ts +6 -0
- package/dist/dts/main/budget-controller.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +30 -0
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/vendor-picker-controller.d.ts +89 -0
- package/dist/dts/main/vendor-picker-controller.d.ts.map +1 -0
- package/dist/dts/provider/ai-provider-switcher.d.ts +22 -1
- package/dist/dts/provider/ai-provider-switcher.d.ts.map +1 -1
- package/dist/dts/provider/tiered-provider-switcher.d.ts +39 -2
- package/dist/dts/provider/tiered-provider-switcher.d.ts.map +1 -1
- package/dist/esm/chat-driver-node.js +1 -1
- package/dist/esm/components/chat-driver/chat-driver.js +3 -2
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +1 -0
- package/dist/esm/components/settings-modal/settings-modal.js +4 -1
- package/dist/esm/components/settings-modal/settings-modal.styles.js +59 -0
- package/dist/esm/components/settings-modal/settings-modal.template.js +54 -1
- package/dist/esm/genesis/register-genesis-assistant.js +72 -7
- package/dist/esm/genesis/vendor-follower.js +149 -0
- package/dist/esm/genesis/vendor-pick.js +67 -0
- package/dist/esm/main/budget-controller.js +11 -9
- package/dist/esm/main/main.js +57 -0
- package/dist/esm/main/vendor-picker-controller.js +141 -0
- package/dist/esm/provider/tiered-provider-switcher.js +54 -1
- package/docs/genesis.md +35 -1
- package/package.json +17 -17
|
@@ -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
|
|
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(', ')}
|
|
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 = (
|
|
804
|
-
const budgets = (
|
|
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
|
package/dist/esm/main/main.js
CHANGED
|
@@ -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);
|
|
@@ -29,7 +29,9 @@ export class TieredAIProviderSwitcher {
|
|
|
29
29
|
"vendor's requests to one vendor's proxy.");
|
|
30
30
|
}
|
|
31
31
|
this.options = options;
|
|
32
|
-
this.
|
|
32
|
+
this.vendorChoice = options.vendorChoice;
|
|
33
|
+
this.builtVendors = (_a = options.vendors) !== null && _a !== void 0 ? _a : AI_TIER_VENDORS;
|
|
34
|
+
this._vendors = this.builtVendors;
|
|
33
35
|
// Same reasoning as the endpoint check: fail here, not a turn at a time later. Booting on a
|
|
34
36
|
// vendor outside `vendors` serves one the app has just declared it cannot reach, and is a
|
|
35
37
|
// one-way door — `switchTo` refuses to go back to it once anything switches away. An empty
|
|
@@ -52,6 +54,57 @@ export class TieredAIProviderSwitcher {
|
|
|
52
54
|
get vendor() {
|
|
53
55
|
return this._vendor;
|
|
54
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The vendors it can switch between now: `vendors` as constructed, unless
|
|
59
|
+
* {@link TieredAIProviderSwitcher.setAvailableVendors} has narrowed them since.
|
|
60
|
+
*/
|
|
61
|
+
get vendors() {
|
|
62
|
+
return this._vendors;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Change which vendors are available, within the ones it was constructed with, and optionally
|
|
66
|
+
* which one is active — in one registry rebuild.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* For a host that learns at runtime which vendors its proxy can serve. Genesis Create's preview
|
|
70
|
+
* is the one today: the app is built before the user picks a vendor there, so it registers every
|
|
71
|
+
* vendor and narrows to the ones Create offers once it has asked. The standby entries follow
|
|
72
|
+
* the list, so the assistant's budget-wall banner offers a switch only to a vendor that can
|
|
73
|
+
* answer.
|
|
74
|
+
*
|
|
75
|
+
* `active` is adopted the way {@link TieredAIProviderSwitcher.adoptPersistedVendor} adopts a
|
|
76
|
+
* vendor: subscribers hear of a change, `onSwitch` does not fire. Left out, the active vendor
|
|
77
|
+
* stays when the new list keeps it and becomes the list's first when it does not.
|
|
78
|
+
*
|
|
79
|
+
* Ignored as a whole — nothing changes — when no listed vendor is one it was constructed with,
|
|
80
|
+
* or when `active` is not in the list. A call that changes neither the list nor the vendor
|
|
81
|
+
* leaves the registry alone, so a host may repeat it as often as it asks.
|
|
82
|
+
*/
|
|
83
|
+
setAvailableVendors(vendors, active) {
|
|
84
|
+
const next = this.builtVendors.filter((v) => vendors.includes(v));
|
|
85
|
+
if (!next.length)
|
|
86
|
+
return;
|
|
87
|
+
let target;
|
|
88
|
+
if (active === undefined) {
|
|
89
|
+
target = next.includes(this._vendor) ? this._vendor : next[0];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const named = next.find((v) => v === active);
|
|
93
|
+
if (!named)
|
|
94
|
+
return;
|
|
95
|
+
target = named;
|
|
96
|
+
}
|
|
97
|
+
const sameList = next.length === this._vendors.length && next.every((v) => this._vendors.includes(v));
|
|
98
|
+
if (sameList && target === this._vendor)
|
|
99
|
+
return;
|
|
100
|
+
this._vendors = next;
|
|
101
|
+
this.registry.update(this.build(target), { default: this.defaultTier });
|
|
102
|
+
const changed = target !== this._vendor;
|
|
103
|
+
this._vendor = target;
|
|
104
|
+
if (changed)
|
|
105
|
+
for (const listener of Array.from(this.listeners))
|
|
106
|
+
listener(target);
|
|
107
|
+
}
|
|
55
108
|
/**
|
|
56
109
|
* A user-driven switch: move the registry, then tell the app so it can persist the choice.
|
|
57
110
|
* An unknown vendor is ignored.
|
package/docs/genesis.md
CHANGED
|
@@ -67,11 +67,45 @@ could only ever answer for a generated tool whose description the model still se
|
|
|
67
67
|
| `config` | — | The app's `GenesisAiConfig`. |
|
|
68
68
|
| `container` | the DOM DI container | Where the tier providers are registered. |
|
|
69
69
|
| `endpointBase` | `<PUBLIC_PATH>/gwf/ai-service` | `/<vendor>/chat` is appended. Unset, the build env's `GENX_AI_CHAT_BASE` wins (Create's preview; never an app file). |
|
|
70
|
-
| `vendors` | `[config.vendor]` | Vendors the
|
|
70
|
+
| `vendors` | `[config.vendor]` | Vendors the chat starts with. One by default: a proxy holding one key cannot answer for another vendor. The proxy's answer replaces them (see below). |
|
|
71
71
|
| `connect` | the app's `Connect`, from DI | Resolved when a tool first runs, not at registration. |
|
|
72
72
|
| `extensions` | none | `{ toolDefinitions, toolHandlers, systemPrompt }` — the app's hand-written tools, added after the generated ones. |
|
|
73
73
|
| `rowSources` | the `REQ_` for the same table | **Deprecated.** Only the table's own `REQ_` is accepted, which is the default. See [Write tools](#write-tools). |
|
|
74
74
|
|
|
75
|
+
#### Which vendors the chat uses
|
|
76
|
+
|
|
77
|
+
The chat asks its AI proxy which vendors it can serve: `GET <base>/vendor`, at the same base it
|
|
78
|
+
posts `/<vendor>/chat` to (`endpointBase`, else `GENX_AI_CHAT_BASE`, else
|
|
79
|
+
`<PUBLIC_PATH>/gwf/ai-service`), with credentials and `cache: 'no-store'`. The proxy answers
|
|
80
|
+
`{ "vendor": "anthropic", "offeredVendors": ["gemini", "anthropic"] }`.
|
|
81
|
+
|
|
82
|
+
- **An exported app's own proxy** offers the vendors whose `AI_<VENDOR>_API_KEY` is set on the
|
|
83
|
+
app's server, and needs the `AI_CHAT` right, like the chat routes.
|
|
84
|
+
- **Genesis Create's preview** names the vendor the user has selected in Create, and the vendors
|
|
85
|
+
Create can serve. The chat follows a change made in Create without a reload.
|
|
86
|
+
|
|
87
|
+
The chat starts on `config.vendor` (or the app's `vendors`), then takes the proxy's `vendor` and
|
|
88
|
+
offers a switch only among `offeredVendors` that the tier table knows, so a budget wall names only
|
|
89
|
+
a vendor that can answer. It asks at registration, when the window regains focus or the tab becomes
|
|
90
|
+
visible, and after each turn, and applies an answer only while no turn is running.
|
|
91
|
+
|
|
92
|
+
**Picking a vendor.** In an exported app, the assistant's Settings show a card per vendor in the AI
|
|
93
|
+
model section once the proxy offers two or more. The cards are the `settings-model` slot's fallback
|
|
94
|
+
content, so an app that slots its own control there keeps only its own. A pick is remembered per signed-in user and app in
|
|
95
|
+
`localStorage` (guarded, and kept in memory when storage is unavailable), and the chat keeps it
|
|
96
|
+
across refreshes and reloads for as long as the proxy still offers it; when it no longer does, the
|
|
97
|
+
proxy's `vendor` takes over. The cards are disabled while a turn is computing. In Create's preview
|
|
98
|
+
the user picks in Create, so Settings show the active vendor read-only ("AI vendor: Anthropic,
|
|
99
|
+
selected in Genesis Create.") and the chat keeps following the proxy. A budget wall's banner names
|
|
100
|
+
the place to switch: "in Settings", or "in Genesis Create".
|
|
101
|
+
|
|
102
|
+
An empty `offeredVendors` (no key is set) puts the chat back on what it started on, so its
|
|
103
|
+
requests reach the proxy's `NO_API_KEY` refusal and the user reads why. Anything else leaves the
|
|
104
|
+
chat where it is, which before the first good answer is exactly what it
|
|
105
|
+
was before this request existed: the configured vendor alone. That covers a 404 (a proxy too old to
|
|
106
|
+
answer), a 403 (a user without `AI_CHAT`), a network error, another shape, or a `vendor` that is
|
|
107
|
+
not offered. These are logged at debug level only.
|
|
108
|
+
|
|
75
109
|
The agent runs on the registry's default provider, which is the configured tier. Its system prompt
|
|
76
110
|
is the configured prompt, then a fixed rule that tool results are app data and never
|
|
77
111
|
instructions, then its one exception (a change request the user typed into a write review, see
|