Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(templates): choose a managed agent's provider from its machine's report

Petr Bauchc0493ac62166
diff --git a/console/apps/switch-console-desktop/src/renderer/features/templates/template-use-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/templates/template-use-view.tsx
index 1719c2c28..307a36a0a 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/templates/template-use-view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/templates/template-use-view.tsx
@@ -16,6 +16,7 @@ import type {
TemplateRunResult,
} from '@main/core/switch-servers/gateway-client';
import type { GuardResult, ViewDefinition } from '@renderer/app/view-registry';
+import { machineProviderOptions } from '@renderer/features/locations/components/add-agent-modal/machine-provider-picker';
import { machineLabel } from '@renderer/features/locations/components/add-agent-modal/server-run-locations';
import { agentsStore } from '@renderer/features/locations/stores/agents-store';
import { HostReachabilityNotice } from '@renderer/features/remote-hosts/host-reachability-notice';
@@ -745,6 +746,14 @@ const TemplateUsePanel = observer(function TemplateUsePanel() {
: machinesQuery.data === null
? []
: undefined;
+ } else if (param.type === 'provider' && management) {
+ // The providers its machine last reported ready; none to go by until it has a machine.
+ const machine = setups[agentIndexOf(param)]?.machine;
+ candidates = machine
+ ? machineProviderOptions(machine)
+ .filter((option) => option.ready)
+ .map((option) => option.id)
+ : undefined;
} else if (param.type === 'provider') {
// The providers installed where the agent reading this param runs.
const at = setups[agentIndexOf(param)];
@@ -1663,8 +1672,10 @@ const TemplateUsePanel = observer(function TemplateUsePanel() {
}
: null;
- /** The SSH host of the agent a param is read by, for a control that depends on that machine. */
+ /** The SSH host of the agent a param is read by, for a control that depends on that machine.
+ * With agent management a `location` holds one of the deployer's machines, not an SSH host. */
const sshHostOf = (param: ParamSpec): string | null => {
+ if (management) return null;
const location = setups[agentIndexOf(param)]?.location ?? null;
return location === null || location === LOCAL_RUN_LOCATION ? null : location;
};
@@ -1729,6 +1740,8 @@ const TemplateUsePanel = observer(function TemplateUsePanel() {
sshHost={sshHostOf(param)}
hosts={allowedHosts}
machines={machines}
+ serverId={serverId}
+ managedMachine={management ? (setups[agentIndexOf(param)]?.machine ?? null) : null}
locationAsMachine={management}
newRoom={newRoomForPick}
disabled={busy}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/templates/use/param-field.tsx b/console/apps/switch-console-desktop/src/renderer/features/templates/use/param-field.tsx
index 5132baa9a..896ad2ad7 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/templates/use/param-field.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/templates/use/param-field.tsx
@@ -1,12 +1,14 @@
import type { ParamSpec } from '@main/core/room-templates/controller';
import { AgentTypePicker } from '@renderer/features/locations/components/add-agent-modal/agent-type-picker';
import { LocalDirectorySelector } from '@renderer/features/locations/components/add-agent-modal/local-directory-selector';
+import { MachineProviderPicker } from '@renderer/features/locations/components/add-agent-modal/machine-provider-picker';
import {
AgentField,
BridgeField,
type EntityLists,
UserField,
} from '@renderer/features/room-templates/entity-fields';
+import { useAppSettingsKey } from '@renderer/features/settings/use-app-settings-key';
import { Input } from '@renderer/lib/ui/input';
import { Switch } from '@renderer/lib/ui/switch';
import { Textarea } from '@renderer/lib/ui/textarea';
@@ -27,6 +29,8 @@ export function ParamField({
sshHost,
hosts,
machines,
+ serverId,
+ managedMachine,
locationAsMachine,
newRoom,
disabled,
@@ -43,6 +47,10 @@ export function ParamField({
hosts: readonly { sshHost: string; name: string }[];
/** The owner's machines a `machine` param may name; null without agent management. */
machines: readonly OwnedMachine[] | null;
+ serverId: string;
+ /** With agent management, the machine the agent reading this param runs on, whose
+ * reported providers a `provider` is chosen from; null until it has one. */
+ managedMachine: OwnedMachine | null;
/** On a server with agent management, a `location` is one of the deployer's machines there. */
locationAsMachine: boolean;
/** For a `room` param: the room the template creates, offered as `$new`. */
@@ -52,6 +60,7 @@ export function ParamField({
}) {
const required = isRequired(param);
const strVal = typeof value === 'string' ? value : String(value ?? '');
+ const { value: defaultAgent } = useAppSettingsKey('defaultAgent');
const showDefault = param.default !== null && !isChain(param) && param.type !== 'boolean';
let control: React.ReactNode;
@@ -66,6 +75,20 @@ export function ParamField({
{value ? 'Yes' : 'No'}
</label>
);
+ } else if (param.type === 'provider' && locationAsMachine) {
+ control = managedMachine ? (
+ <MachineProviderPicker
+ serverId={serverId}
+ machine={managedMachine}
+ value={(strVal || null) as AgentProviderId | null}
+ onChange={(id) => onChange(id)}
+ defaultAgent={defaultAgent}
+ />
+ ) : (
+ <p className="text-xs text-foreground-muted">
+ Choose a machine first: the providers offered are the ones it has ready.
+ </p>
+ );
} else if (param.type === 'provider') {
control = (
<AgentTypePicker