UNPKG

@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;" />

57 lines (55 loc) 2.61 kB
require("reflect-metadata"); const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs'); const require_learning = require('../core/learning.cjs'); const require_runtime$1 = require('../core/runtime.cjs'); const require_client = require('../intelligence-platform/client.cjs'); const require_resolve_intelligence_user = require('./shared/resolve-intelligence-user.cjs'); let _copilotkit_shared = require("@copilotkit/shared"); //#region src/v2/runtime/handlers/handle-inspector-learning.ts const headers = { "Cache-Control": "no-store, private", "Content-Type": "application/json" }; const errorResponse = (status, message) => new Response(JSON.stringify({ error: message }), { status, headers }); const queryPage = (value) => value === null ? void 0 : Number(value); /** Proxies a bounded Learning read through the runtime's server-held credential. */ async function handleInspectorLearning({ runtime, request }) { if (!require_runtime$1.isIntelligenceRuntime(runtime) || !require_learning.hasLearningContainerConfiguration(runtime)) return errorResponse(404, "Not found"); const user = await require_resolve_intelligence_user.resolveIntelligenceUser({ runtime, request }); if (user instanceof Response) return user; const url = new URL(request.url); if ([...url.searchParams.keys()].some((key) => ![ "agentId", "skillsPage", "insightsPage" ].includes(key))) return errorResponse(400, "Invalid Inspector Learning request"); const parsedRequest = (0, _copilotkit_shared.parseInspectorLearningRequestV1)({ agentId: url.searchParams.get("agentId") ?? void 0, skillsPage: queryPage(url.searchParams.get("skillsPage")), insightsPage: queryPage(url.searchParams.get("insightsPage")) }); if (!parsedRequest) return errorResponse(400, "Invalid Inspector Learning request"); try { const snapshot = (0, _copilotkit_shared.parseInspectorLearningSnapshotV1)(await runtime.intelligence.getInspectorLearning({ ...parsedRequest, ...typeof runtime.learning?.containerId === "string" ? { runtimeContainerId: runtime.learning.containerId } : {} })); if (!snapshot) return errorResponse(502, "Invalid Inspector Learning response"); return new Response(JSON.stringify(snapshot), { status: 200, headers }); } catch (error) { if (error instanceof require_client.PlatformRequestError && error.status === 404) return errorResponse(404, "Not found"); return errorResponse(503, "Inspector Learning is temporarily unavailable"); } } //#endregion exports.handleInspectorLearning = handleInspectorLearning; //# sourceMappingURL=handle-inspector-learning.cjs.map