Skip to content

Commit

Permalink
implement semdex not enabled states
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Dec 20, 2024
1 parent 170fd4b commit 55fcb58
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
13 changes: 13 additions & 0 deletions app/transports/http/bindings/datagraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/Southclaws/storyden/app/resources/profile"
"github.com/Southclaws/storyden/app/services/search/searcher"
"github.com/Southclaws/storyden/app/services/semdex"
"github.com/Southclaws/storyden/app/services/system/instance_info"
"github.com/Southclaws/storyden/app/transports/http/openapi"
)

Expand All @@ -28,6 +29,7 @@ type Datagraph struct {
}

func NewDatagraph(
info *instance_info.Provider,
searcher searcher.Searcher,
asker semdex.Asker,
router *echo.Echo,
Expand All @@ -37,12 +39,23 @@ func NewDatagraph(
asker: asker,
}

ii, err := info.Get(context.Background())
if err != nil {
panic(err)
}

isEnabled := ii.Capabilities.Has(instance_info.CapabilitySemdex)

// The generated OpenAPI code does not expose the underlying ResponseWriter
// which we need for streaming Q&A responses for that ✨chatgpt✨ effect.
router.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
path := c.Path()
if path == "/api/datagraph/qna" {
if !isEnabled {
return echo.NewHTTPError(http.StatusNotImplemented, "Semdex is not enabled")
}

ctx := c.Request().Context()

query := c.QueryParam("q")
Expand Down
7 changes: 5 additions & 2 deletions web/src/components/site/Navigation/DesktopCommandBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getServerSession } from "@/auth/server-session";
import { hasCapability } from "@/lib/settings/capabilities";
import { getSettings } from "@/lib/settings/settings-server";
import { cx } from "@/styled-system/css";
import { HStack } from "@/styled-system/jsx";
Expand All @@ -14,11 +15,13 @@ import { getServerSidebarState } from "./NavigationPane/server";
import { Title } from "./Title";

export async function DesktopCommandBar() {
const { title } = await getSettings();
const { title, capabilities } = await getSettings();
const initialSidebarState = await getServerSidebarState();

const session = await getServerSession();

const isSemdexEnabled = hasCapability("semdex", capabilities);

return (
<HStack
className={cx(Floating(), styles["topbar"])}
Expand All @@ -30,7 +33,7 @@ export async function DesktopCommandBar() {
<HStack className={styles["topbar-left"]}>
<SidebarToggle initialValue={initialSidebarState} />
<SearchAnchor />
<AskAnchor />
{isSemdexEnabled && <AskAnchor />}
</HStack>

<HStack className={styles["topbar-middle"]} justify="space-around">
Expand Down
16 changes: 10 additions & 6 deletions web/src/screens/ask/AskScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ import { useNodeGet } from "@/api/openapi-client/nodes";
import { useThreadGet } from "@/api/openapi-client/threads";
import { DatagraphItemKind } from "@/api/openapi-schema";
import {
DatagraphItemBadge,
DatagraphItemCard,
DatagraphItemNodeCard,
DatagraphItemPostGenericCard,
} from "@/components/datagraph/DatagraphItemCard";
import { Unready } from "@/components/site/Unready";
import { UnreadyBanner } from "@/components/site/Unready";
import { Spinner } from "@/components/ui/Spinner";
import { Button } from "@/components/ui/button";
import { Heading } from "@/components/ui/heading";
import { Input } from "@/components/ui/input";
import { API_ADDRESS, WEB_ADDRESS } from "@/config";
import { DatagraphKindSchema } from "@/lib/datagraph/schema";
import { useCapability } from "@/lib/settings/capabilities";
import { css } from "@/styled-system/css";
import { Box, CardBox, LStack, styled } from "@/styled-system/jsx";
import { Box, LStack, styled } from "@/styled-system/jsx";
import { hstack, lstack } from "@/styled-system/patterns";
import { deriveError } from "@/utils/error";

type DatagraphRef = {
id: string;
Expand All @@ -37,6 +34,7 @@ export function AskScreen() {
const [content, setContent] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [sources, setSources] = useState<Record<string, DatagraphRef>>({});
const isEnabled = useCapability("semdex");

useEffect(() => {
// Helper to extract SDR references from content
Expand Down Expand Up @@ -143,6 +141,12 @@ export function AskScreen() {

const sourceList = values(sources);

if (!isEnabled) {
return (
<UnreadyBanner error="Ask mode is not enabled for this installation." />
);
}

return (
<LStack>
<styled.form
Expand Down

0 comments on commit 55fcb58

Please sign in to comment.