Skip to content

Commit 2bdb62f

Browse files
committed
feat(inspector): make inspector compatible with new architecture
1 parent 17d09e8 commit 2bdb62f

File tree

6 files changed

+56
-79
lines changed

6 files changed

+56
-79
lines changed

frontend/src/app/connect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function Connect({
7272
<ConnectionForm
7373
ref={formRef}
7474
defaultValues={{
75-
username: search.u || "http://localhost:8080",
75+
username: search.u || "http://localhost:6420",
7676
token: search.t || "",
7777
}}
7878
onSubmit={onSubmit}

frontend/src/app/data-providers/inspector-data-provider.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,8 @@ function transformActor(a: InspectorActor): Actor {
176176

177177
export function createClient({ url, token }: { url: string; token: string }) {
178178
const newUrl = new URL(url);
179-
if (!newUrl.pathname.endsWith("registry/inspect")) {
180-
if (!newUrl.pathname.endsWith("registry")) {
181-
newUrl.pathname = `${ensureTrailingSlash(newUrl.pathname)}registry`;
182-
}
183-
if (!newUrl.pathname.endsWith("inspect")) {
184-
newUrl.pathname = `${ensureTrailingSlash(newUrl.pathname)}inspect`;
185-
}
179+
if (!newUrl.pathname.endsWith("inspect")) {
180+
newUrl.pathname = `${ensureTrailingSlash(newUrl.pathname)}inspect`;
186181
}
187182

188183
return createManagerInspectorClient(newUrl.href, {

frontend/src/components/actors/guard-connectable-inspector.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useMutation, useQuery, useSuspenseQuery } from "@tanstack/react-query";
33
import { useMatch } from "@tanstack/react-router";
44
import { type ReactNode, useMemo } from "react";
55
import { useInspectorCredentials } from "@/app/credentials-context";
6-
import { createEngineActorContext } from "@/queries/actor-engine";
76
import { createInspectorActorContext } from "@/queries/actor-inspector";
87
import { DiscreteCopyButton } from "../copy-area";
8+
import { getConfig } from "../lib/config";
99
import { Button } from "../ui/button";
1010
import { useFiltersValue } from "./actor-filters-context";
1111
import { ActorProvider } from "./actor-queries-context";
@@ -77,16 +77,7 @@ function ActorContextProvider(props: {
7777
);
7878
}
7979

80-
function ActorInspectorProvider({
81-
actorId,
82-
children,
83-
}: {
84-
actorId: ActorId;
85-
children: ReactNode;
86-
}) {
87-
const { data } = useSuspenseQuery(
88-
useDataProvider().actorQueryOptions(actorId),
89-
);
80+
function ActorInspectorProvider({ children }: { children: ReactNode }) {
9081
const { credentials } = useInspectorCredentials();
9182

9283
if (!credentials?.url || !credentials?.token) {
@@ -96,9 +87,8 @@ function ActorInspectorProvider({
9687
const actorContext = useMemo(() => {
9788
return createInspectorActorContext({
9889
...credentials,
99-
name: data.name || "",
10090
});
101-
}, [credentials, data.name]);
91+
}, [credentials]);
10292

10393
return <ActorProvider value={actorContext}>{children}</ActorProvider>;
10494
}
@@ -135,7 +125,8 @@ function useActorEngineContext({ actorId }: { actorId: ActorId }) {
135125
const { actor, runner } = useActorRunner({ actorId });
136126

137127
const actorContext = useMemo(() => {
138-
return createEngineActorContext({
128+
return createInspectorActorContext({
129+
url: getConfig().apiUrl,
139130
token: (runner?.metadata?.inspectorToken as string) || "",
140131
});
141132
}, [runner?.metadata?.inspectorToken]);

frontend/src/queries/actor-engine.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createActorInspectorClient } from "@rivetkit/core/inspector";
21
import {
32
type ActorContext,
43
createDefaultActorContext,
@@ -8,43 +7,28 @@ import { ensureTrailingSlash } from "@/lib/utils";
87
export const createInspectorActorContext = ({
98
url,
109
token,
11-
name,
1210
}: {
1311
url: string;
1412
token: string;
15-
name: string;
1613
}) => {
1714
const def = createDefaultActorContext();
1815
const newUrl = new URL(url);
19-
if (!newUrl.pathname.endsWith("registry/inspect")) {
20-
if (!newUrl.pathname.endsWith("registry")) {
21-
newUrl.pathname = `${ensureTrailingSlash(newUrl.pathname)}registry`;
22-
}
23-
if (!newUrl.pathname.endsWith("inspect")) {
24-
newUrl.pathname = `${ensureTrailingSlash(newUrl.pathname)}inspect`;
25-
}
16+
if (!newUrl.pathname.endsWith("inspect")) {
17+
newUrl.pathname = `${ensureTrailingSlash(newUrl.pathname)}inspect`;
2618
}
27-
newUrl.pathname = newUrl.pathname.replace(
28-
"/registry/inspect",
29-
"/registry/actors/inspect",
30-
);
3119
return {
3220
...def,
3321
createActorInspectorFetchConfiguration(actorId) {
3422
return {
3523
headers: {
36-
"X-RivetKit-Query": JSON.stringify({
37-
getForId: { actorId, name },
38-
}),
39-
Authorization: `Bearer ${token}`,
24+
"x-rivet-actor": actorId,
25+
"x-rivet-target": "actor",
26+
...(token ? { authorization: `Bearer ${token}` } : {}),
4027
},
4128
};
4229
},
43-
createActorInspector(actorId) {
44-
return createActorInspectorClient(
45-
newUrl.href,
46-
this.createActorInspectorFetchConfiguration(actorId),
47-
);
30+
createActorInspectorUrl() {
31+
return new URL(`${url}/inspect`, window.location.origin).href;
4832
},
4933
} satisfies ActorContext;
5034
};

frontend/src/routes/_context.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import { createFileRoute, Outlet } from "@tanstack/react-router";
1+
import {
2+
createFileRoute,
3+
Outlet,
4+
useNavigate,
5+
useParams,
6+
} from "@tanstack/react-router";
27
import { zodValidator } from "@tanstack/zod-adapter";
38
import { match } from "ts-pattern";
49
import z from "zod";
510
import { createGlobalContext as createGlobalCloudContext } from "@/app/data-providers/cloud-data-provider";
611
import { createGlobalContext as createGlobalEngineContext } from "@/app/data-providers/engine-data-provider";
712
import { createGlobalContext as createGlobalInspectorContext } from "@/app/data-providers/inspector-data-provider";
13+
import { useDialog } from "@/components/hooks/use-dialog";
814

915
const searchSchema = z
1016
.object({
@@ -49,5 +55,38 @@ export const Route = createFileRoute("/_context")({
4955
});
5056

5157
function RouteComponent() {
52-
return <Outlet />;
58+
return (
59+
<>
60+
<Outlet />
61+
<Modals />
62+
</>
63+
);
64+
}
65+
66+
function Modals() {
67+
const navigate = useNavigate();
68+
const search = Route.useSearch();
69+
const params = useParams({ strict: false });
70+
71+
const CreateActorDialog = useDialog.CreateActor.Dialog;
72+
73+
return (
74+
<CreateActorDialog
75+
namespace={params.namespace || ""}
76+
dialogProps={{
77+
open: search.modal === "create-actor",
78+
onOpenChange: (value) => {
79+
if (!value) {
80+
navigate({
81+
to: ".",
82+
search: (old) => ({
83+
...old,
84+
modal: undefined,
85+
}),
86+
});
87+
}
88+
},
89+
}}
90+
/>
91+
);
5392
}

0 commit comments

Comments
 (0)