Skip to content

Commit

Permalink
fix: overlay infinite loader and not allowed model (Issue #100, #512) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mikitabut authored Jan 15, 2024
1 parent b662a20 commit bbe67f9
Show file tree
Hide file tree
Showing 26 changed files with 387 additions and 237 deletions.
3 changes: 0 additions & 3 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ DIAL_API_VERSION="2023-03-15-preview"
# App Settings
APP_BASE_PATH=""

# AUTH
AUTH_DISABLED="false"

## NextAuth (more info https://next-auth.js.org/configuration/options)
# NEXTAUTH_URL=""
NEXTAUTH_SECRET=""
Expand Down
73 changes: 37 additions & 36 deletions README.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/OVERLAY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ Need to disable authentication and allow iframe origin
e.g.

```
AUTH_DISABLED=true
ALLOWED_IFRAME_ORIGINS=*
```

or

```
AUTH_DISABLED=true
ALLOWED_IFRAME_ORIGINS=http://127.0.0.1:8000
```

Expand Down
1 change: 0 additions & 1 deletion environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ declare global {
STORAGE_TYPE?: string;
TRACES_URL?: string;

AUTH_DISABLED?: string;
NEXTAUTH_URL?: string;
NEXTAUTH_SECRET?: string;
AUTH_TEST_TOKEN?: string;
Expand Down
44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@opentelemetry/exporter-trace-otlp-proto": "^0.43.0",
"@opentelemetry/instrumentation": "^0.43.0",
"@opentelemetry/instrumentation-http": "^0.43.0",
"@opentelemetry/instrumentation-pino": "^0.34.5",
"@opentelemetry/resources": "^1.17.0",
"@opentelemetry/sdk-metrics": "^1.17.0",
"@opentelemetry/sdk-node": "^0.43.0",
Expand Down
12 changes: 6 additions & 6 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const Chat = memo(() => {
const models = useAppSelector(ModelsSelectors.selectModels);
const modelsMap = useAppSelector(ModelsSelectors.selectModelsMap);
const modelError = useAppSelector(ModelsSelectors.selectModelsError);
const modelsIsLoading = useAppSelector(ModelsSelectors.selectModelsIsLoading);
const isModelsLoaded = useAppSelector(ModelsSelectors.selectIsModelsLoaded);
const defaultModelId = useAppSelector(SettingsSelectors.selectDefaultModelId);
const addons = useAppSelector(AddonsSelectors.selectAddons);
const addonsMap = useAppSelector(AddonsSelectors.selectAddonsMap);
Expand Down Expand Up @@ -143,9 +143,9 @@ export const Chat = memo(() => {

useEffect(() => {
const modelIds = models.map((model) => model.id);
const isNotAllowedModel = modelsIsLoading
? false
: models.length === 0 ||
const isNotAllowedModel =
isModelsLoaded &&
(models.length === 0 ||
selectedConversations.some((conv) => {
if (
conv.replay.isReplay &&
Expand All @@ -161,7 +161,7 @@ export const Chat = memo(() => {
);
}
return !modelIds.includes(conv.model.id);
});
}));
if (isNotAllowedModel) {
setNotAllowedType(EntityType.Model);
} else if (
Expand All @@ -173,7 +173,7 @@ export const Chat = memo(() => {
} else {
setNotAllowedType(null);
}
}, [selectedConversations, models, modelsIsLoading, addonsMap]);
}, [selectedConversations, models, isModelsLoaded, addonsMap]);

const onLikeHandler = useCallback(
(index: number, conversation: Conversation) => (rate: number) => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Chat/ChatInput/ChatInputMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const ChatInputMessage = ({
const notModelConversations = useAppSelector(
ConversationsSelectors.selectNotModelConversations,
);
const isModelsLoading = useAppSelector(ModelsSelectors.selectModelsIsLoading);
const isModelsLoaded = useAppSelector(ModelsSelectors.selectIsModelsLoaded);
const isChatFullWidth = useAppSelector(UISelectors.selectIsChatFullWidth);

const isError =
Expand Down Expand Up @@ -140,7 +140,7 @@ export const ChatInputMessage = ({
isReplay ||
isError ||
isInputEmpty ||
isModelsLoading ||
!isModelsLoaded ||
isUploadingFilePresent;

const handleChange = useCallback(
Expand Down Expand Up @@ -301,7 +301,7 @@ export const ChatInputMessage = ({
'Please wait for full assistant answer to continue working with chat',
);
}
if (isModelsLoading) {
if (!isModelsLoaded) {
return t(
'Please wait for models will be loaded to continue working with chat',
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Files/AttachButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const AttachButton = ({
const messageIsStreaming = useAppSelector(
ConversationsSelectors.selectIsConversationsStreaming,
);
const isModelsLoading = useAppSelector(ModelsSelectors.selectModelsIsLoading);
const isModelLoaded = useAppSelector(ModelsSelectors.selectIsModelsLoaded);
const availableAttachmentsTypes = useAppSelector(
ConversationsSelectors.selectAvailableAttachmentsTypes,
);
Expand Down Expand Up @@ -80,7 +80,7 @@ export const AttachButton = ({
TriggerIcon={IconPaperclip}
triggerIconSize={24}
triggerTooltip={t('Attach files') || ''}
disabled={messageIsStreaming || isModelsLoading}
disabled={messageIsStreaming || !isModelLoaded}
triggerIconHighlight
/>
{isSelectFilesDialogOpened && (
Expand Down
3 changes: 2 additions & 1 deletion src/opentelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pkg from '../package.json';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
import { Resource } from '@opentelemetry/resources';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { SpanExporter } from '@opentelemetry/sdk-trace-base';
Expand Down Expand Up @@ -32,7 +33,7 @@ const sdk = new NodeSDK({
[SemanticResourceAttributes.SERVICE_VERSION]: pkg.version,
}),
),
instrumentations: [new HttpInstrumentation()],
instrumentations: [new HttpInstrumentation(), new PinoInstrumentation()],
spanProcessor,
});
sdk.start();
130 changes: 3 additions & 127 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,133 +1,9 @@
import type { AuthOptions, CookiesOptions } from 'next-auth';
import NextAuth from 'next-auth/next';
import { Provider } from 'next-auth/providers';
import Auth0Provider from 'next-auth/providers/auth0';
import AzureProvider from 'next-auth/providers/azure-ad';
import GoogleProvider from 'next-auth/providers/google';
import KeycloakProvider from 'next-auth/providers/keycloak';

import { GitLab } from '../../../utils/auth/custom-gitlab';
import PingId from '../../../utils/auth/ping-identity';
import { callbacks, tokenConfig } from '@/src/utils/auth/nextauth';
import { logger } from '@/src/utils/server/logger';
import { callbacks } from '@/src/utils/auth/auth-callbacks';
import { authProviders } from '@/src/utils/auth/auth-providers';

const DEFAULT_NAME = 'SSO';

const allProviders: (Provider | boolean)[] = [
!!process.env.AUTH_AZURE_AD_CLIENT_ID &&
!!process.env.AUTH_AZURE_AD_SECRET &&
!!process.env.AUTH_AZURE_AD_TENANT_ID &&
AzureProvider({
clientId: process.env.AUTH_AZURE_AD_CLIENT_ID,
clientSecret: process.env.AUTH_AZURE_AD_SECRET,
tenantId: process.env.AUTH_AZURE_AD_TENANT_ID,
name: process.env.AUTH_AZURE_AD_NAME ?? DEFAULT_NAME,
authorization: {
params: {
scope:
process.env.AUTH_AZURE_AD_SCOPE ||
'openid profile user.Read email offline_access',
},
},
token: tokenConfig,
}),

!!process.env.AUTH_GITLAB_CLIENT_ID &&
!!process.env.AUTH_GITLAB_SECRET &&
GitLab({
clientId: process.env.AUTH_GITLAB_CLIENT_ID,
clientSecret: process.env.AUTH_GITLAB_SECRET,
name: process.env.AUTH_GITLAB_NAME ?? DEFAULT_NAME,
gitlabHost: process.env.AUTH_GITLAB_HOST,
authorization: {
params: { scope: process.env.AUTH_GITLAB_SCOPE || 'read_user' },
},
token: tokenConfig,
}),

!!process.env.AUTH_GOOGLE_CLIENT_ID &&
!!process.env.AUTH_GOOGLE_SECRET &&
GoogleProvider({
clientId: process.env.AUTH_GOOGLE_CLIENT_ID,
clientSecret: process.env.AUTH_GOOGLE_SECRET,
name: process.env.AUTH_GOOGLE_NAME ?? DEFAULT_NAME,
authorization: {
params: {
scope:
process.env.AUTH_GOOGLE_SCOPE ||
'openid email profile offline_access',
},
},
token: tokenConfig,
}),

!!process.env.AUTH_AUTH0_CLIENT_ID &&
!!process.env.AUTH_AUTH0_SECRET &&
!!process.env.AUTH_AUTH0_HOST &&
Auth0Provider({
clientId: process.env.AUTH_AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH_AUTH0_SECRET,
name: process.env.AUTH_AUTH0_NAME ?? DEFAULT_NAME,
issuer: process.env.AUTH_AUTH0_HOST,
authorization: {
params: {
audience: process.env.AUTH_AUTH0_AUDIENCE,
scope:
process.env.AUTH_AUTH0_SCOPE ||
'openid email profile offline_access',
},
},
token: tokenConfig,
}),

!!process.env.AUTH_PING_ID_CLIENT_ID &&
!!process.env.AUTH_PING_ID_SECRET &&
!!process.env.AUTH_PING_ID_HOST &&
PingId({
clientId: process.env.AUTH_PING_ID_CLIENT_ID,
clientSecret: process.env.AUTH_PING_ID_SECRET,
name: process.env.AUTH_PING_ID_NAME ?? DEFAULT_NAME,
issuer: process.env.AUTH_PING_ID_HOST,
authorization: {
params: {
scope: process.env.AUTH_PING_ID_SCOPE || 'offline_access',
},
},
token: tokenConfig,
}),

!!process.env.AUTH_KEYCLOAK_CLIENT_ID &&
!!process.env.AUTH_KEYCLOAK_SECRET &&
!!process.env.AUTH_KEYCLOAK_HOST &&
KeycloakProvider({
clientId: process.env.AUTH_KEYCLOAK_CLIENT_ID,
clientSecret: process.env.AUTH_KEYCLOAK_SECRET,
name: process.env.AUTH_KEYCLOAK_NAME ?? DEFAULT_NAME,
issuer: process.env.AUTH_KEYCLOAK_HOST,
userinfo: {
async request(context) {
const userinfo = await context.client.userinfo(
context.tokens.access_token as string,
);
return userinfo;
},
},
authorization: {
params: {
scope:
process.env.AUTH_KEYCLOAK_SCOPE ||
'openid email profile offline_access',
},
},
token: tokenConfig,
}),
];

const providers = allProviders.filter(Boolean) as Provider[];

if (!providers.length && process.env.AUTH_DISABLED !== 'true') {
logger.error('No auth providers!');
}
// https://github.com/nextauthjs/next-auth/blob/a8dfc8ebb11ccb96fd694db888e52f0d20395e64/packages/core/src/lib/cookie.ts#L53
function defaultCookies(
useSecureCookies: boolean,
Expand Down Expand Up @@ -201,7 +77,7 @@ const isSecure =
!!process.env.NEXTAUTH_URL && process.env.NEXTAUTH_URL.startsWith('https:');

export const authOptions: AuthOptions = {
providers,
providers: authProviders,
cookies: defaultCookies(isSecure, isSecure ? 'none' : 'lax'),
callbacks,
session: {
Expand Down
Loading

0 comments on commit bbe67f9

Please sign in to comment.