Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import * as Effect from "effect/Effect";import { bodyJson } from "../server/http";import type { SkillInspection } from "../shared/skill-management";import type { SkillListing } from "../shared/skills";import { runAgent } from "./agent-io";import { OperationFailure } from "./operation-result";import type { PersonalSkills } from "./personal-skills";import type { ValidatedSkillPackage } from "./skill-package";
export function inspectSkillPackage( skill: SkillListing, loaded: ValidatedSkillPackage,): SkillInspection { const { entry } = loaded; return { skill, instructions: entry.body, license: entry.license, compatibility: entry.compatibility, metadata: entry.metadata, allowedTools: entry.allowedTools ?? null, files: loaded.files.map((file) => { const resource = entry.resources?.find( (resource) => resource.path === file.path, ); return { path: file.path, encoding: file.encoding, bytes: resource?.size ?? new TextEncoder().encode(file.content).byteLength, kind: file.path === "SKILL.md" ? "instructions" : (resource?.kind ?? "file"), mimeType: resource?.mimeType, }; }), };}
export function handleSkillManagement( request: Request, skills: PersonalSkills,) { const failure = (code: string, message: string, status: number) => Response.json( { error: { code, message, path: "" } }, { status, headers: { "Cache-Control": "no-store" } }, ); if (request.method !== "POST") return Promise.resolve( failure("method_not_allowed", "Use POST for Skill management.", 405), ); return runAgent( bodyJson( new Response(request.body, { headers: request.headers }), 4096, new OperationFailure("skill_invalid_request"), ).pipe( Effect.flatMap((value) => skills.manage(value)), Effect.map((result) => Response.json(result, { headers: { "Cache-Control": "no-store" } }), ), Effect.timeoutOrElse({ duration: 15_000, orElse: () => Effect.fail(new Error("Skill request timed out")), }), Effect.catch((error) => Effect.succeed( error instanceof OperationFailure ? failure( error.code, error.message, error.code === "skill_invalid_request" || error.code === "skill_file_missing" || error.code === "skill_bundled" ? 400 : 409, ) : failure( "skill_unavailable", "Could not complete this Skill request. Reload Skills and try again.", 503, ), ), ), Effect.catchDefect(() => Effect.succeed( failure( "skill_unavailable", "Skill management is unavailable. Try again.", 500, ), ), ), ), request.signal, );}