Skip to content

Commit

Permalink
Merge branch 'main' into Matvey-Kuk/better-demo-alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk authored Nov 24, 2024
2 parents 6afe255 + d9cf4e3 commit 7766c9e
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 77 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

<div align="center">
<a href='http://makeapullrequest.com'>
<img alt='PRs Welcome' src='https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=shields'/>
</a>
<img alt='PRs Welcome' src='https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=shields'/></a>
<a href="https://slack.keephq.dev">
<img src="https://img.shields.io/badge/Join-important.svg?color=4A154B&label=Slack&logo=slack&labelColor=334155&logoColor=f5f5f5" alt="Join Slack" /></a>
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/keephq/keep"/>
<a href="https://github.com/keephq/keep/commits/main">
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/keephq/keep"/></a>
<a href="https://codecov.io/gh/keephq/keep" >
<img src="https://codecov.io/gh/keephq/keep/branch/main/graph/badge.svg?token=2VT6XYMRGS"/>
</a>
Expand Down
14 changes: 14 additions & 0 deletions keep-ui/app/(keep)/incidents/[id]/chat/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@

import { IncidentChat } from "./incident-chat";
import { IncidentDto } from "@/entities/incidents/model";
import { EmptyStateCard } from "@/shared/ui";
import { useConfig } from "@/utils/hooks/useConfig";
import { CopilotKit } from "@copilotkit/react-core";
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";

export function IncidentChatClientPage({
incident,
}: {
incident: IncidentDto;
}) {
const { data: config } = useConfig();
if (config && !config.OPEN_AI_API_KEY_SET) {
return (
<EmptyStateCard
icon={ExclamationTriangleIcon}
title="Chat is not available"
description="The OpenAI API key is not set. Ask your administrator to set it to enable chat."
/>
);
}

return (
<CopilotKit runtimeUrl="/api/copilotkit">
<IncidentChat incident={incident} />
Expand Down
21 changes: 21 additions & 0 deletions keep-ui/app/api/aws-marketplace/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NextRequest } from "next/server";
import { redirect } from "next/navigation";

export async function POST(request: NextRequest) {
try {
// In App Router, we need to parse the request body manually
const body = await request.json();

const token = body["x-amzn-marketplace-token"];
const offerType = body["x-amzn-marketplace-offer-type"];

// Base64 encode the token
const base64EncodedToken = encodeURIComponent(btoa(token));

// In App Router, we use the redirect function for redirects
return redirect(`/signin?amt=${base64EncodedToken}`);
} catch (error) {
console.error("Error processing request:", error);
return new Response("Bad Request", { status: 400 });
}
}
41 changes: 41 additions & 0 deletions keep-ui/app/api/copilotkit/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import OpenAI, { OpenAIError } from "openai";
import { NextRequest } from "next/server";

function initializeCopilotRuntime() {
try {
const openai = new OpenAI({
organization: process.env.OPEN_AI_ORGANIZATION_ID,
apiKey: process.env.OPEN_AI_API_KEY,
});
const serviceAdapter = new OpenAIAdapter({ openai });
const runtime = new CopilotRuntime();
return { runtime, serviceAdapter };
} catch (error) {
if (error instanceof OpenAIError) {
console.log("Error connecting to OpenAI", error);
} else {
console.error("Error initializing Copilot Runtime", error);
}
return null;
}
}

const runtimeOptions = initializeCopilotRuntime();

export const POST = async (req: NextRequest) => {
if (!runtimeOptions) {
return new Response("Error initializing Copilot Runtime", { status: 500 });
}
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime: runtimeOptions.runtime,
serviceAdapter: runtimeOptions.serviceAdapter,
endpoint: "/api/copilotkit",
});

return handleRequest(req);
};
1 change: 0 additions & 1 deletion keep-ui/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
8 changes: 4 additions & 4 deletions keep-ui/package-lock.json

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

2 changes: 1 addition & 1 deletion keep-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"moment": "^2.29.4",
"next": "^14.2.13",
"next-auth": "^5.0.0-beta.25",
"openai": "^4.72.0",
"openai": "^4.73.0",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
"postcss-js": "^4.0.1",
Expand Down
17 changes: 0 additions & 17 deletions keep-ui/pages/_error.jsx

This file was deleted.

23 changes: 0 additions & 23 deletions keep-ui/pages/api/aws-marketplace.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions keep-ui/pages/api/copilotkit.ts

This file was deleted.

1 change: 1 addition & 0 deletions keep-ui/shared/lib/server/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ export function getConfig() {
POSTHOG_HOST: process.env.POSTHOG_HOST,
SENTRY_DISABLED: process.env.SENTRY_DISABLED,
READ_ONLY: process.env.KEEP_READ_ONLY === "true",
OPEN_AI_API_KEY_SET: !!process.env.OPEN_AI_API_KEY,
};
}
36 changes: 36 additions & 0 deletions keep-ui/shared/ui/EmptyState/EmptyStateCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Card } from "@tremor/react";
import { CircleStackIcon } from "@heroicons/react/24/outline";
import clsx from "clsx";

export function EmptyStateCard({
title,
icon,
description,
className,
children,
}: {
icon?: React.ElementType;
title: string;
description: string;
className?: string;
children?: React.ReactNode;
}) {
const Icon = icon || CircleStackIcon;
return (
<Card className={clsx("sm:mx-auto w-full max-w-5xl", className)}>
<div className="text-center">
<Icon
className="mx-auto h-7 w-7 text-tremor-content-subtle dark:text-dark-tremor-content-subtle"
aria-hidden={true}
/>
<p className="mt-2 text-tremor-default font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong">
{title}
</p>
<p className="text-tremor-default text-tremor-content dark:text-dark-tremor-content">
{description}
</p>
{children}
</div>
</Card>
);
}
1 change: 1 addition & 0 deletions keep-ui/shared/ui/EmptyState/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmptyStateCard } from "./EmptyStateCard";
1 change: 1 addition & 0 deletions keep-ui/shared/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { TablePagination } from "./TablePagination";
export { TabLinkNavigation, TabNavigationLink } from "./TabLinkNavigation";
export { DateTimeField } from "./DateTimeField";
export { FieldHeader } from "./FieldHeader";
export { EmptyStateCard } from "./EmptyState";
1 change: 1 addition & 0 deletions keep-ui/types/internal-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface InternalConfig {
SENTRY_DISABLED: string;
// READ ONLY
READ_ONLY: boolean;
OPEN_AI_API_KEY_SET: boolean;
}

0 comments on commit 7766c9e

Please sign in to comment.