refac
This commit is contained in:
@@ -146,33 +146,7 @@
|
|||||||
let webSearchEnabled = false;
|
let webSearchEnabled = false;
|
||||||
let codeInterpreterEnabled = false;
|
let codeInterpreterEnabled = false;
|
||||||
|
|
||||||
// Auto-inject direct terminal servers into selected tool IDs so they act like toggled-on tools
|
|
||||||
// System terminals (with id field) are handled server-side via terminal_id, not as direct tool servers
|
|
||||||
$: if ($terminalServers && $terminalServers.length > 0) {
|
|
||||||
const directTerminalServers = $terminalServers.filter((t) => !t.id);
|
|
||||||
const terminalIds = directTerminalServers.map(
|
|
||||||
(_, i) => `direct_server:terminal_${$terminalServers.indexOf(directTerminalServers[i])}`
|
|
||||||
);
|
|
||||||
const missingIds = terminalIds.filter((id) => !selectedToolIds.includes(id));
|
|
||||||
if (missingIds.length > 0) {
|
|
||||||
selectedToolIds = [...selectedToolIds, ...missingIds];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove disabled terminal servers from selectedToolIds automatically
|
|
||||||
$: if (selectedToolIds.length > 0) {
|
|
||||||
const directTerminalServers = ($terminalServers ?? []).filter((t) => !t.id);
|
|
||||||
const terminalIds = directTerminalServers.map(
|
|
||||||
(_, i) =>
|
|
||||||
`direct_server:terminal_${($terminalServers ?? []).indexOf(directTerminalServers[i])}`
|
|
||||||
);
|
|
||||||
const invalidTerminalIds = selectedToolIds.filter(
|
|
||||||
(id) => id.startsWith('direct_server:terminal_') && !terminalIds.includes(id)
|
|
||||||
);
|
|
||||||
if (invalidTerminalIds.length > 0) {
|
|
||||||
selectedToolIds = selectedToolIds.filter((id) => !invalidTerminalIds.includes(id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let showCommands = false;
|
let showCommands = false;
|
||||||
|
|
||||||
@@ -354,25 +328,12 @@
|
|||||||
[...(model?.info?.meta?.toolIds ?? [])].filter((id) => $tools.find((t) => t.id === id))
|
[...(model?.info?.meta?.toolIds ?? [])].filter((id) => $tools.find((t) => t.id === id))
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
} else if (
|
} else if ($settings?.tools) {
|
||||||
$settings?.tools &&
|
|
||||||
$settings.tools.some((id) => !id.startsWith('direct_server:terminal_'))
|
|
||||||
) {
|
|
||||||
selectedToolIds = $settings.tools;
|
selectedToolIds = $settings.tools;
|
||||||
} else {
|
} else {
|
||||||
// Don't wipe existing terminal servers if no default tool IDs
|
|
||||||
selectedToolIds = selectedToolIds.filter((id) => !id.startsWith('direct_server:'));
|
selectedToolIds = selectedToolIds.filter((id) => !id.startsWith('direct_server:'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-inject direct terminal servers (system ones are handled via terminal_id)
|
|
||||||
if ($terminalServers && $terminalServers.length > 0) {
|
|
||||||
const directTerminalServers = $terminalServers.filter((t) => !t.id);
|
|
||||||
const terminalIds = directTerminalServers.map(
|
|
||||||
(_, i) => `direct_server:terminal_${$terminalServers.indexOf(directTerminalServers[i])}`
|
|
||||||
);
|
|
||||||
selectedToolIds = [...new Set([...selectedToolIds, ...terminalIds])];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set Default Filters (Toggleable only)
|
// Set Default Filters (Toggleable only)
|
||||||
if (model?.info?.meta?.defaultFilterIds) {
|
if (model?.info?.meta?.defaultFilterIds) {
|
||||||
selectedFilterIds = model.info.meta.defaultFilterIds.filter((id) =>
|
selectedFilterIds = model.info.meta.defaultFilterIds.filter((id) =>
|
||||||
@@ -2210,7 +2171,9 @@
|
|||||||
tool_servers: [
|
tool_servers: [
|
||||||
...($toolServers ?? []).filter(
|
...($toolServers ?? []).filter(
|
||||||
(server, idx) => toolServerIds.includes(idx) || toolServerIds.includes(server?.id)
|
(server, idx) => toolServerIds.includes(idx) || toolServerIds.includes(server?.id)
|
||||||
)
|
),
|
||||||
|
// Direct terminal servers — always included when enabled (not routed through selectedToolIds)
|
||||||
|
...($terminalServers ?? []).filter((t) => !t.id)
|
||||||
],
|
],
|
||||||
features: getFeatures(),
|
features: getFeatures(),
|
||||||
variables: {
|
variables: {
|
||||||
|
|||||||
@@ -1636,12 +1636,10 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="ml-1 flex gap-1.5">
|
<div class="ml-1 flex gap-1.5">
|
||||||
{#if (selectedToolIds ?? []).filter((id) => !id.startsWith('direct_server:terminal_')).length > 0}
|
{#if (selectedToolIds ?? []).length > 0}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={$i18n.t('{{COUNT}} Available Tools', {
|
content={$i18n.t('{{COUNT}} Available Tools', {
|
||||||
COUNT: (selectedToolIds ?? []).filter(
|
COUNT: (selectedToolIds ?? []).length
|
||||||
(id) => !id.startsWith('direct_server:terminal_')
|
|
||||||
).length
|
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@@ -1655,9 +1653,7 @@
|
|||||||
<Wrench className="size-4" strokeWidth="1.75" />
|
<Wrench className="size-4" strokeWidth="1.75" />
|
||||||
|
|
||||||
<span class="text-sm">
|
<span class="text-sm">
|
||||||
{(selectedToolIds ?? []).filter(
|
{(selectedToolIds ?? []).length}
|
||||||
(id) => !id.startsWith('direct_server:terminal_')
|
|
||||||
).length}
|
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedToolIds = selectedToolIds.filter(
|
selectedToolIds = selectedToolIds.filter(
|
||||||
(id) => Object.keys(tools).includes(id) || id.startsWith('direct_server:terminal_')
|
(id) => Object.keys(tools).includes(id)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -239,6 +239,16 @@
|
|||||||
connect();
|
connect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reconnect when the selected terminal changes
|
||||||
|
$: if ($selectedTerminalId !== undefined && term) {
|
||||||
|
// Clear the terminal screen and reconnect to the new server
|
||||||
|
disconnect();
|
||||||
|
term.clear();
|
||||||
|
if ($selectedTerminalId) {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
initTerminal();
|
initTerminal();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user