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
35 changes: 19 additions & 16 deletions src/mirror/status/status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MirrorRuntimeHost } from "../../mirror-service/index.js";
import {
getMirrordaemonHealthState,
getMirrordaemonProvidersState,
getMirrordaemonRuntimeState,
} from "../../mirrordaemon/index.js";

Expand Down Expand Up @@ -50,7 +51,6 @@ export type GetMirrorStatusOptions = {

export async function getMirrorStatus(opts: GetMirrorStatusOptions): Promise<MirrorStatus> {
const daemon = opts.runtimeHost.daemon;
const boot = daemon.getBootSnapshot();
const peers = opts.runtimeHost.syncManager.listPeers();
const baseUrl = opts.runtimeHost.syncManager.getLocalBaseUrl();
const runtime = getMirrordaemonRuntimeState(daemon, {
Expand All @@ -62,23 +62,26 @@ export async function getMirrorStatus(opts: GetMirrorStatusOptions): Promise<Mir
baseUrl,
peers,
});
const providers = getMirrordaemonProvidersState(daemon, {
providerPlane: opts.runtimeHost.providerPlane,
});

return {
runtime,
service: {
lore_dir: boot.config.lore_dir,
provider_url: boot.config.provider_url,
operator_auth_configured: boot.config.operator_auth_configured,
workspace_users_root: boot.config.workspace_users_root,
lore_dir: health.service.lore_dir,
provider_url: health.service.provider_url,
operator_auth_configured: health.service.operator_auth_configured,
workspace_users_root: runtime.readiness.workspace.users_root,
},
provider: {
configured: health.provider.configured,
ready: health.provider.ready,
active_provider_id: health.provider.active_provider_id,
total: health.provider.total,
available: health.provider.available,
fallback_available: health.provider.fallback_available,
providers: opts.runtimeHost.providerPlane.listProviders().map((provider) => ({
active_provider_id: providers.active_provider_id,
total: providers.total,
available: providers.available,
fallback_available: providers.fallback_available,
providers: providers.providers.map((provider) => ({
provider_id: provider.provider_id,
label: provider.label,
url: provider.url,
Expand All @@ -88,16 +91,16 @@ export async function getMirrorStatus(opts: GetMirrorStatusOptions): Promise<Mir
})),
},
lore: {
ready: boot.readiness.lore.ready,
discovered_files: boot.readiness.lore.discovered_files,
dir: boot.config.lore_dir,
ready: runtime.readiness.lore.ready,
discovered_files: runtime.readiness.lore.discovered_files,
dir: health.service.lore_dir,
},
workspace: {
ready: boot.readiness.workspace.ready,
users_root: boot.readiness.workspace.users_root,
ready: runtime.readiness.workspace.ready,
users_root: runtime.readiness.workspace.users_root,
},
sync: {
node_id: boot.readiness.sync.node_id,
node_id: runtime.node_id,
base_url: health.service.base_url,
peers_known: health.sync.peers_known,
},
Expand Down
3 changes: 3 additions & 0 deletions src/mirror/status/tests/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe("mirror status", () => {
expect(status.runtime.node_id).toBe("status-node");
expect(status.runtime.sessions.total).toBe(0);
expect(status.service.lore_dir).toBe(path.resolve(loreDir));
expect(status.lore.dir).toBe(status.service.lore_dir);
expect(status.service.workspace_users_root).toBe(status.workspace.users_root);
expect(status.provider.configured).toBe(false);
expect(status.provider.active_provider_id).toBe("primary");
expect(status.provider.total).toBe(1);
Expand Down Expand Up @@ -71,6 +73,7 @@ describe("mirror status", () => {

expect(status.runtime.sessions.total).toBe(1);
expect(status.runtime.sessions.open).toBe(1);
expect(status.sync.node_id).toBe(status.runtime.node_id);
expect(status.provider.providers[0]?.provider_id).toBe("primary");

const json = JSON.stringify(status);
Expand Down
2 changes: 2 additions & 0 deletions src/mirrordaemon/daemon_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ export type MirrordaemonProvidersSummary = {
provider_id: string;
label: string;
kind: string;
url: string;
ready: boolean;
configured: boolean;
selected: boolean;
last_error?: string;
}>;
};

Expand Down
62 changes: 62 additions & 0 deletions src/mirrordaemon/runtime_state.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
buildProvidersSummary,
buildDebugSnapshot,
buildHealthSummary,
buildRuntimeSummary,
Expand Down Expand Up @@ -227,4 +228,65 @@ describe("mirrordaemon runtime state", () => {
expect(health.event_stream.recent_events).toBe(daemon.getRecentEvents().length);
expect(health.sync.peers_known).toBe(2);
});

it("includes provider url and last_error in the daemon provider summary", () => {
const daemon = createMirrordaemon({
config: baseConfig,
lifecycle: {
discoveredLoreFiles: 2,
shutdown: async () => undefined,
},
runtimeStartedAt: "2026-03-13T00:00:00.000Z",
});

const providers = buildProvidersSummary(daemon, {
providerPlane: {
listProviders: () => [
{
provider_id: "primary",
label: "Primary",
kind: "openai-compatible",
url: "http://brain.local/v1/chat/completions",
ready: true,
configured: true,
selected: true,
last_error: undefined,
},
{
provider_id: "fallback",
label: "Fallback",
kind: "openai-compatible",
url: "http://brain.local/v1/fallback",
ready: false,
configured: false,
selected: false,
last_error: "provider unavailable",
},
],
} as never,
});

expect(providers.providers).toEqual([
{
provider_id: "primary",
label: "Primary",
kind: "openai-compatible",
url: "http://brain.local/v1/chat/completions",
ready: true,
configured: true,
selected: true,
last_error: undefined,
},
{
provider_id: "fallback",
label: "Fallback",
kind: "openai-compatible",
url: "http://brain.local/v1/fallback",
ready: false,
configured: false,
selected: false,
last_error: "provider unavailable",
},
]);
});
});
2 changes: 2 additions & 0 deletions src/mirrordaemon/runtime_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ export function buildProvidersSummary(
provider_id: provider.provider_id,
label: provider.label,
kind: provider.kind,
url: provider.url,
ready: provider.ready,
configured: provider.configured,
selected: provider.selected,
last_error: provider.last_error,
})) ?? [];

return {
Expand Down
Loading