Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/backend/src/create-backend-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ export function createBackendHost(options: CreateBackendHostOptions = {}): Backe
if (!durableActor) throw new Error("Model offering actor is required");
const actor = await identity.resolveDurableActor(durableActor);
if (!actor) throw new Error("Model offering is not available");
return identity.resolveModelOfferingForUse(actor, offeringId);
return {
...(await identity.resolveModelOfferingForUse(actor, offeringId)),
executionScope: "host" as const,
};
}
: undefined,
authorizeSkillManagement: identity
Expand Down Expand Up @@ -215,7 +218,6 @@ export function createBackendHost(options: CreateBackendHostOptions = {}): Backe
}
c.set("actor", actor);
const humanAdminOnly =
c.req.path.startsWith("/api/host/auth/") ||
c.req.path.startsWith("/api/host/mcp-connections") ||
(c.req.path === "/api/host/custom-instructions" && c.req.method !== "GET") ||
(c.req.path.startsWith("/api/host/skills") &&
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/host/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function createHostContext(
resolveModelOffering?: (
offeringId: string,
actor?: DurableActor,
) => Promise<{ connectionId: string; modelId: string }>;
) => Promise<{ connectionId: string; modelId: string; executionScope: "host" }>;
homeDirectory?: string;
skillSourceResolver?: SkillSourceResolver;
authorizeSkillManagement?: (actor: DurableActor | undefined) => Promise<void>;
Expand Down
36 changes: 36 additions & 0 deletions packages/backend/src/host/opengui-host.auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,42 @@ describe("OpenGuiHost authentication persistence", () => {
await restarted.close();
}
});
test("refreshes the Codex catalog when only personal subscriptions exist", async () => {
const dataDirectory = await directory();
const initial = new OpenGuiHost(dataDirectory, {
fetchImpl: vi.fn().mockRejectedValue("offline"),
});
await initial.start();
await initial.setCustomInstructions("initialize state");
await initial.close();
const statePath = join(dataDirectory, HOST_STATE_FILENAME);
const state = JSON.parse(await readFile(statePath, "utf8"));
state.secrets.personalCodexTokens = {
"member-1": {
connectionId: "personal-opaque",
tokens: {
accessToken: "access",
refreshToken: "refresh",
accountId: "account",
expiresAt: Date.now() + 3_600_000,
},
},
};
await writeFile(statePath, JSON.stringify(state));
const fetchImpl = vi.fn(async () => Response.json({}));
const host = new OpenGuiHost(dataDirectory, { fetchImpl: fetchImpl as typeof fetch });

await host.start();
try {
expect(fetchImpl).toHaveBeenCalledWith(
"https://pi.dev/api/models/providers/openai-codex",
expect.any(Object),
);
} finally {
await host.close();
}
});

test("keeps durable provider continuation state out of snapshots and events", async () => {
const dataDirectory = await directory();
const host = new OpenGuiHost(dataDirectory, {
Expand Down
Loading