{"version":3,"file":"memory-policy.cjs","names":["errorResponse"],"sources":["../../../../../src/v2/runtime/handlers/shared/memory-policy.ts"],"sourcesContent":["import type {\n  CopilotIntelligenceRuntimeLike,\n  CopilotRuntimeUser,\n  MemoryConsumer,\n  MemoryGrant,\n} from \"../../core/runtime\";\nimport { errorResponse } from \"./json-response\";\n\nconst ACCESS = new Set([\"none\", \"read\", \"read-write\"]);\n\nexport interface ResolvedWebMemory {\n  readonly user: CopilotRuntimeUser;\n  readonly grant: MemoryGrant;\n}\n\n/** Evaluates and validates one configured web Memory policy. */\nexport async function resolveWebMemory(\n  runtime: CopilotIntelligenceRuntimeLike,\n  request: Request,\n  user: CopilotRuntimeUser,\n  consumer: MemoryConsumer,\n): Promise<ResolvedWebMemory | Response> {\n  if (!runtime.memory) {\n    return {\n      user,\n      grant: { user: \"read-write\", project: \"read-write\" },\n    };\n  }\n\n  try {\n    const grant = await runtime.memory.access({ request, user, consumer });\n    if (grant === null || (grant.user === \"none\" && grant.project === \"none\")) {\n      return errorResponse(\"Memory access denied\", 403);\n    }\n    if (!ACCESS.has(grant.user) || !ACCESS.has(grant.project)) {\n      return errorResponse(\"Memory policy returned an invalid grant\", 500);\n    }\n    return { user, grant: { user: grant.user, project: grant.project } };\n  } catch {\n    return errorResponse(\"Memory policy failed\", 500);\n  }\n}\n"],"mappings":";;;;AAQA,MAAM,SAAS,IAAI,IAAI;CAAC;CAAQ;CAAQ;CAAa,CAAC;;AAQtD,eAAsB,iBACpB,SACA,SACA,MACA,UACuC;AACvC,KAAI,CAAC,QAAQ,OACX,QAAO;EACL;EACA,OAAO;GAAE,MAAM;GAAc,SAAS;GAAc;EACrD;AAGH,KAAI;EACF,MAAM,QAAQ,MAAM,QAAQ,OAAO,OAAO;GAAE;GAAS;GAAM;GAAU,CAAC;AACtE,MAAI,UAAU,QAAS,MAAM,SAAS,UAAU,MAAM,YAAY,OAChE,QAAOA,oCAAc,wBAAwB,IAAI;AAEnD,MAAI,CAAC,OAAO,IAAI,MAAM,KAAK,IAAI,CAAC,OAAO,IAAI,MAAM,QAAQ,CACvD,QAAOA,oCAAc,2CAA2C,IAAI;AAEtE,SAAO;GAAE;GAAM,OAAO;IAAE,MAAM,MAAM;IAAM,SAAS,MAAM;IAAS;GAAE;SAC9D;AACN,SAAOA,oCAAc,wBAAwB,IAAI"}