|
1 | 1 | import crypto from "node:crypto";
|
2 | 2 | import { createMiddleware } from "hono/factory";
|
| 3 | +import type { ManagerDriver } from "@/driver-helpers/mod"; |
3 | 4 | import type { RunConfig } from "@/mod";
|
4 | 5 | import type { RunConfigInput } from "@/registry/run-config";
|
5 | 6 | import { inspectorLogger } from "./log";
|
@@ -28,10 +29,6 @@ export function compareSecrets(providedSecret: string, validSecret: string) {
|
28 | 29 |
|
29 | 30 | export const secureInspector = (runConfig: RunConfig) =>
|
30 | 31 | createMiddleware(async (c, next) => {
|
31 |
| - if (!runConfig.inspector.enabled) { |
32 |
| - return c.text("Inspector is not enabled", 503); |
33 |
| - } |
34 |
| - |
35 | 32 | const userToken = c.req.header("Authorization")?.replace("Bearer ", "");
|
36 | 33 | if (!userToken) {
|
37 | 34 | return c.text("Unauthorized", 401);
|
@@ -74,3 +71,25 @@ export function getInspectorUrl(runConfig: RunConfigInput | undefined) {
|
74 | 71 |
|
75 | 72 | return url.href;
|
76 | 73 | }
|
| 74 | + |
| 75 | +export const isInspectorEnabled = ( |
| 76 | + runConfig: RunConfig, |
| 77 | + context: "actor" | "manager", |
| 78 | +) => { |
| 79 | + if (typeof runConfig.inspector?.enabled === "boolean") { |
| 80 | + return runConfig.inspector.enabled; |
| 81 | + } else if (typeof runConfig.inspector?.enabled === "object") { |
| 82 | + return runConfig.inspector.enabled[context]; |
| 83 | + } |
| 84 | + return false; |
| 85 | +}; |
| 86 | + |
| 87 | +export const configureInspectorAccessToken = ( |
| 88 | + runConfig: RunConfig, |
| 89 | + managerDriver: ManagerDriver, |
| 90 | +) => { |
| 91 | + if (!runConfig.inspector?.token()) { |
| 92 | + const token = managerDriver.getOrCreateInspectorAccessToken(); |
| 93 | + runConfig.inspector.token = () => token; |
| 94 | + } |
| 95 | +}; |
0 commit comments