@copilotkit/runtime
Version:
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
135 lines (133 loc) • 5.64 kB
JavaScript
import "reflect-metadata";
import { supportsLocalThreadEndpoints } from "../runner/agent-runner.mjs";
import { isTelemetryDisabled } from "../telemetry/telemetry-client.mjs";
import { VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "../core/runtime.mjs";
import { PlatformRequestError } from "../intelligence-platform/client.mjs";
//#region src/v2/runtime/handlers/get-runtime-info.ts
function resolveLicenseStatus(runtime) {
if (!runtime.licenseChecker) return "none";
const status = runtime.licenseChecker.getStatus();
if (status.warningSeverity === "none") return "valid";
if (status.error === "expired") return "expired";
if (status.warningSeverity === "warning") return "expiring";
if (status.error) return "invalid";
if (status.warningSeverity === "info") return "none";
return "unknown";
}
/**
* Map the structured entitlement authority onto the legacy status consumed by
* older Core, React, and Angular thread surfaces. A ready managed entitlement
* is authoritative in both directions. Otherwise, preserve the legacy
* self-hosted license fallback. A retryable lookup without that fallback
* remains unknown until it resolves.
*/
function resolveCompatibilityLicenseStatus(runtime, runtimeEntitlements) {
if (runtimeEntitlements?.status === "ready") {
if (runtimeEntitlements.entitlement.source === "managedOrgSubscription") return runtimeEntitlements.entitlement.active ? "valid" : "none";
if (runtimeEntitlements.entitlement.active) return "valid";
}
const legacyLicenseStatus = resolveLicenseStatus(runtime);
if (legacyLicenseStatus === "none" && runtimeEntitlements?.status !== "ready" && runtimeEntitlements?.error.retryable) return "unknown";
return legacyLicenseStatus;
}
/**
* Resolve structured Runtime entitlements for configured Intelligence runtimes.
*
* Dependency failures are deliberately converted to a stable unavailable
* diagnostic so `/info` remains an availability endpoint. The underlying
* error is not exposed because it may contain upstream response details.
*/
async function resolveRuntimeEntitlements(runtime) {
if (!isIntelligenceRuntime(runtime)) return;
try {
return await runtime.intelligence.getRuntimeEntitlements();
} catch (error) {
if (error instanceof PlatformRequestError && error.retryable === false) return {
status: "misconfigured",
error: {
code: "runtime_entitlements_misconfigured",
message: "Runtime entitlement lookup is misconfigured",
retryable: false
}
};
return {
status: "unavailable",
error: {
code: "runtime_entitlements_unavailable",
message: "Runtime entitlement lookup failed",
retryable: true
}
};
}
}
async function handleGetRuntimeInfo({ runtime, request, threadEndpointsEnabled = true }) {
try {
const runtimeEntitlementsPromise = resolveRuntimeEntitlements(runtime);
const webEnabled = !isIntelligenceRuntime(runtime) || runtime.identifyUser !== void 0;
const agents = webEnabled ? await resolveAgents(runtime.agents, request) : {};
const agentEntries = await Promise.all(Object.entries(agents).map(async ([name, agent]) => {
let capabilities;
try {
capabilities = agent.getCapabilities ? await agent.getCapabilities() : void 0;
} catch (error) {
console.warn(`Failed to fetch capabilities for agent "${name}":`, error instanceof Error ? error.message : error);
capabilities = void 0;
}
return [name, {
name,
description: agent.description,
className: agent.constructor.name,
...capabilities ? { capabilities } : {}
}];
}));
const agentsDict = Object.fromEntries(agentEntries);
const runtimeEntitlements = await runtimeEntitlementsPromise;
const runtimeInfo = {
version: VERSION,
agents: agentsDict,
audioFileTranscriptionEnabled: webEnabled && !!runtime.transcriptionService,
mode: runtime.mode,
threadEndpoints: resolveThreadEndpointInfo(runtime, threadEndpointsEnabled && webEnabled),
suggestions: webEnabled,
...isIntelligenceRuntime(runtime) && webEnabled ? {
intelligence: { wsUrl: runtime.intelligence.ɵgetClientWsUrl() },
inspectorMetadata: true
} : {},
a2uiEnabled: webEnabled && isA2UIEnabled(runtime.a2ui),
...webEnabled && isA2UIEnabled(runtime.a2ui) ? { a2ui: {
enabled: true,
...runtime.a2ui.agents ? { agents: runtime.a2ui.agents } : {}
} } : {},
openGenerativeUIEnabled: webEnabled && !!runtime.openGenerativeUI,
...isIntelligenceRuntime(runtime) ? { licenseStatus: resolveCompatibilityLicenseStatus(runtime, runtimeEntitlements) } : {},
...runtimeEntitlements ? { runtimeEntitlements } : {},
telemetryDisabled: isTelemetryDisabled()
};
return new Response(JSON.stringify(runtimeInfo), {
status: 200,
headers: { "Content-Type": "application/json" }
});
} catch (error) {
return new Response(JSON.stringify({
error: "Failed to retrieve runtime information",
message: error instanceof Error ? error.message : "Unknown error"
}), {
status: 500,
headers: { "Content-Type": "application/json" }
});
}
}
function resolveThreadEndpointInfo(runtime, threadEndpointsEnabled) {
const hasRestThreadBackend = isIntelligenceRuntime(runtime) || supportsLocalThreadEndpoints(runtime.runner);
const restEndpointsAvailable = threadEndpointsEnabled && hasRestThreadBackend;
const managedThreadMetadata = threadEndpointsEnabled && isIntelligenceRuntime(runtime);
return {
list: restEndpointsAvailable,
inspect: restEndpointsAvailable,
mutations: managedThreadMetadata,
realtimeMetadata: managedThreadMetadata
};
}
//#endregion
export { handleGetRuntimeInfo };
//# sourceMappingURL=get-runtime-info.mjs.map