diff --git a/packages/toolchain/js-utils-embed/js/deno.jsonc b/packages/toolchain/js-utils-embed/js/deno.jsonc index d3662f270c..1893f292bb 100644 --- a/packages/toolchain/js-utils-embed/js/deno.jsonc +++ b/packages/toolchain/js-utils-embed/js/deno.jsonc @@ -38,7 +38,7 @@ "@bartlomieju/postgres": "jsr:@bartlomieju/postgres@^0.17.2", "@cross/dir": "jsr:@cross/dir@^1.1.0", "@hono/hono": "jsr:@hono/hono@^4.6.3", - "@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.11.1", + "@luca/esbuild-deno-loader": "jsr:@rivet-gg/esbuild-deno-loader@^0.10.3-fork.3", "@std/assert": "jsr:@std/assert@0.213", "@std/async": "jsr:@std/async@^1.0.4", "@std/cli": "jsr:@std/cli@^1.0.5", diff --git a/packages/toolchain/toolchain/src/tasks/deploy/manager.rs b/packages/toolchain/toolchain/src/tasks/deploy/manager.rs index a7e48d308b..36a7f216e7 100644 --- a/packages/toolchain/toolchain/src/tasks/deploy/manager.rs +++ b/packages/toolchain/toolchain/src/tasks/deploy/manager.rs @@ -44,15 +44,7 @@ pub async fn deploy( .to_string(), bundler: Some(config::build::javascript::Bundler::Deno), deno: config::build::javascript::Deno { - // TODO(RVT-4382): Does not support workspaces, so we have to point to the - // manager's Deno config - config_path: Some( - manager_src_path - .join("manager") - .join("deno.jsonc") - .display() - .to_string(), - ), + config_path: None, import_map_url: None, lock_path: Some(manager_src_path.join("deno.lock").display().to_string()), }, diff --git a/sdks/actor/manager/package.json b/sdks/actor/manager/package.json index ee73ac4315..296539c3a2 100644 --- a/sdks/actor/manager/package.json +++ b/sdks/actor/manager/package.json @@ -1,5 +1,10 @@ { "name": "@rivet-gg/actor-manager", "version": "24.6.2-rc.1", - "private": true + "private": true, + "dependencies": { + "@rivet-gg/actor-common": "workspace:*", + "@rivet-gg/manager-protocol": "workspace:*", + "hono": "^4.6.17" + } } diff --git a/sdks/actor/manager/src/log.ts b/sdks/actor/manager/src/log.ts index 4728e03a80..ee1d60d227 100644 --- a/sdks/actor/manager/src/log.ts +++ b/sdks/actor/manager/src/log.ts @@ -1,4 +1,5 @@ -import { getLogger } from "../../common/src/log.ts"; +// @ts-types="../../common/dist/log.d.ts" +import { getLogger } from "@rivet-gg/actor-common/log"; export const LOGGER_NAME = "actor-manager"; diff --git a/sdks/actor/manager/src/mod.ts b/sdks/actor/manager/src/mod.ts index 6969f2330a..d32df20a36 100644 --- a/sdks/actor/manager/src/mod.ts +++ b/sdks/actor/manager/src/mod.ts @@ -1,143 +1,124 @@ -import type { ActorContext } from "@rivet-gg/actor-core"; -import { RivetClient } from "@rivet-gg/api"; -import { assertExists } from "@std/assert/exists"; -import { Hono, type Context as HonoContext } from "hono"; -import { cors } from "hono/cors"; -import { setupLogging } from "../../common/src/log.ts"; -import { PORT_NAME } from "../../common/src/network.ts"; -import { - type RivetEnvironment, - assertUnreachable, -} from "../../common/src/utils.ts"; -import { - ActorsRequestSchema, - type ActorsResponse, - type RivetConfigResponse, -} from "../../manager-protocol/src/mod.ts"; -import { logger } from "./log.ts"; -import { queryActor } from "./query_exec.ts"; - -export default class Manager { - private readonly endpoint: string; - private readonly rivetClient: RivetClient; - private readonly environment: RivetEnvironment; - - constructor(private readonly ctx: ActorContext) { - const endpoint = Deno.env.get("RIVET_API_ENDPOINT"); - assertExists(endpoint, "missing RIVET_API_ENDPOINT"); - const token = Deno.env.get("RIVET_SERVICE_TOKEN"); - assertExists(token, "missing RIVET_SERVICE_TOKEN"); - - this.endpoint = endpoint; - - this.rivetClient = new RivetClient({ - environment: endpoint, - token, - }); - - this.environment = { - project: this.ctx.metadata.project.slug, - environment: this.ctx.metadata.environment.slug, - }; - } - - static async start(ctx: ActorContext) { - setupLogging(); - - // biome-ignore lint/complexity/noThisInStatic: Must be used for default actor entrypoint - const manager = new this(ctx); - await manager.#run(); - } - - async #run() { - const portStr = Deno.env.get("PORT_HTTP"); - if (!portStr) throw "Missing port"; - const port = Number.parseInt(portStr); - if (!Number.isFinite(port)) throw "Invalid port"; - - const app = new Hono(); - - app.use( - "/*", - cors({ - origin: (origin) => { - return origin.includes("localhost"); - }, - }), - ); - - app.get("/rivet/config", (c: HonoContext) => { - return c.json({ - // HACK(RVT-4376): Replace DNS address used for local dev envs with public address - endpoint: this.endpoint.replace("rivet-server", "127.0.0.1"), - project: this.environment.project, - environment: this.environment.environment, - } satisfies RivetConfigResponse); - }); - - app.post("/actors", async (c: HonoContext) => { - // Get actor - const body = ActorsRequestSchema.parse(await c.req.json()); - const actor = await queryActor( - this.rivetClient, - this.environment, - body.query, - ); - - // Fetch port - const httpPort = actor.network.ports[PORT_NAME]; - assertExists(httpPort, "missing port"); - const hostname = httpPort.hostname; - assertExists(hostname); - const port = httpPort.port; - assertExists(port); - - let isTls = false; - switch (httpPort.protocol) { - case "https": - isTls = true; - break; - case "http": - case "tcp": - isTls = false; - break; - case "tcp_tls": - case "udp": - throw new Error(`Invalid protocol ${httpPort.protocol}`); - default: - assertUnreachable(httpPort.protocol); - } - - const path = httpPort.path ?? ""; - - const endpoint = `${ - isTls ? "https" : "http" - }://${hostname}:${port}${path}`; - - return c.json({ endpoint } satisfies ActorsResponse); - }); - - app.all("*", (c) => { - return c.text("Not Found", 404); - }); - - logger().info("server running", { port }); - const server = Deno.serve( - { - port, - hostname: "0.0.0.0", - // Remove "Listening on ..." message - onListen() {}, - }, - app.fetch, - ); - - logger().debug("rivet endpoint", { - endpoint: this.endpoint, - project: this.ctx.metadata.project.slug, - environment: this.ctx.metadata.environment.slug, - }); - - await server.finished; - } -} +//export default class Manager { +// private readonly endpoint: string; +// private readonly rivetClient: RivetClient; +// private readonly environment: RivetEnvironment; +// +// constructor(private readonly ctx: ActorContext) { +// const endpoint = Deno.env.get("RIVET_API_ENDPOINT"); +// assertExists(endpoint, "missing RIVET_API_ENDPOINT"); +// const token = Deno.env.get("RIVET_SERVICE_TOKEN"); +// assertExists(token, "missing RIVET_SERVICE_TOKEN"); +// +// this.endpoint = endpoint; +// +// this.rivetClient = new RivetClient({ +// environment: endpoint, +// token, +// }); +// +// this.environment = { +// project: this.ctx.metadata.project.slug, +// environment: this.ctx.metadata.environment.slug, +// }; +// } +// +// static async start(ctx: ActorContext) { +// setupLogging(); +// +// // biome-ignore lint/complexity/noThisInStatic: Must be used for default actor entrypoint +// const manager = new this(ctx); +// await manager.#run(); +// } +// +// async #run() { +// const portStr = Deno.env.get("PORT_HTTP"); +// if (!portStr) throw "Missing port"; +// const port = Number.parseInt(portStr); +// if (!Number.isFinite(port)) throw "Invalid port"; +// +// const app = new Hono(); +// +// app.use( +// "/*", +// cors({ +// origin: (origin) => { +// return origin.includes("localhost"); +// }, +// }), +// ); +// +// app.get("/rivet/config", (c: HonoContext) => { +// return c.json({ +// // HACK(RVT-4376): Replace DNS address used for local dev envs with public address +// endpoint: this.endpoint.replace("rivet-server", "127.0.0.1"), +// project: this.environment.project, +// environment: this.environment.environment, +// } satisfies RivetConfigResponse); +// }); +// +// app.post("/actors", async (c: HonoContext) => { +// // Get actor +// const body = ActorsRequestSchema.parse(await c.req.json()); +// const actor = await queryActor( +// this.rivetClient, +// this.environment, +// body.query, +// ); +// +// // Fetch port +// const httpPort = actor.network.ports[PORT_NAME]; +// assertExists(httpPort, "missing port"); +// const hostname = httpPort.hostname; +// assertExists(hostname); +// const port = httpPort.port; +// assertExists(port); +// +// let isTls = false; +// switch (httpPort.protocol) { +// case "https": +// isTls = true; +// break; +// case "http": +// case "tcp": +// isTls = false; +// break; +// case "tcp_tls": +// case "udp": +// throw new Error(`Invalid protocol ${httpPort.protocol}`); +// default: +// assertUnreachable(httpPort.protocol); +// } +// +// const path = httpPort.path ?? ""; +// +// const endpoint = `${ +// isTls ? "https" : "http" +// }://${hostname}:${port}${path}`; +// +// return c.json({ endpoint } satisfies ActorsResponse); +// }); +// +// app.all("*", (c) => { +// return c.text("Not Found", 404); +// }); +// +// logger().info("server running", { port }); +// const server = Deno.serve( +// { +// port, +// hostname: "0.0.0.0", +// // Remove "Listening on ..." message +// onListen() {}, +// }, +// app.fetch, +// ); +// +// logger().debug("rivet endpoint", { +// endpoint: this.endpoint, +// project: this.ctx.metadata.project.slug, +// environment: this.ctx.metadata.environment.slug, +// }); +// +// await server.finished; +// } +//} diff --git a/sdks/actor/manager/src/query_exec.ts b/sdks/actor/manager/src/query_exec.ts index b2c03c807b..d3b67fc041 100644 --- a/sdks/actor/manager/src/query_exec.ts +++ b/sdks/actor/manager/src/query_exec.ts @@ -1,16 +1,20 @@ -import type { Rivet, RivetClient } from "@rivet-gg/api"; -import { assertEquals } from "@std/assert"; -import { PORT_NAME } from "../../common/src/network.ts"; -import { assertUnreachable } from "../../common/src/utils.ts"; +// @ts-types="../../common/dist/network.d.ts" +import { PORT_NAME } from "@rivet-gg/actor-common/network"; +// @ts-types="../../common/dist/utils.d.ts" +import { assertUnreachable } from "@rivet-gg/actor-common/utils"; +// @ts-types="../../common/dist/utils.d.ts" import type { ActorTags, BuildTags, RivetEnvironment, -} from "../../common/src/utils.ts"; +} from "@rivet-gg/actor-common/utils"; +import type { Rivet, RivetClient } from "@rivet-gg/api"; +// @ts-types="../../manager-protocol/dist/query.d.ts" import type { ActorQuery, CreateRequest, -} from "../../manager-protocol/src/query.ts"; +} from "@rivet-gg/manager-protocol/query"; +import { assertEquals } from "@std/assert"; import { logger } from "./log.ts"; export async function queryActor(