import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
import {
  __export
} from "./chunk-HSLMI22Q.mjs";

// src/core/capability.ts
var capability_exports = {};
__export(capability_exports, {
  ModuleTag: () => ModuleTag,
  Service: () => Service,
  atom: () => atom,
  contributes: () => contributes,
  get: () => get,
  getAll: () => getAll,
  getModuleTag: () => getModuleTag,
  lazy: () => lazy,
  make: () => make,
  makeModule: () => makeModule,
  waitFor: () => waitFor
});
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
var Service = class extends Context.Tag("@dxos/app-framework/CapabilityManager")() {
};
var get = (interfaceDef) => Effect.flatMap(Service, (manager) => Effect.try({
  try: () => manager.get(interfaceDef),
  catch: (error) => error instanceof Error ? error : new Error(String(error))
}));
var getAll = (interfaceDef) => Effect.map(Service, (manager) => manager.getAll(interfaceDef));
var waitFor = (interfaceDef) => Effect.flatMap(Service, (manager) => manager.waitFor(interfaceDef));
var atom = (interfaceDef) => Effect.map(Service, (manager) => manager.atom(interfaceDef));
var InterfaceDefTypeId = Symbol.for("InterfaceDefTypeId");
var ModuleTag = Symbol.for("@dxos/app-framework/ModuleTag");
var make = (identifier) => {
  return {
    identifier
  };
};
var contributes = (interfaceDef, implementation, deactivate) => {
  return {
    interface: interfaceDef,
    implementation,
    deactivate
  };
};
var lazy = (name, c) => {
  const lazyFn = (props) => Effect.gen(function* () {
    const { default: getCapability } = yield* Effect.tryPromise(() => c());
    const result = yield* getCapability(props);
    const normalized = result == null ? [] : Array.isArray(result) ? Array.from(result) : [
      result
    ];
    return normalized;
  });
  return Object.assign(lazyFn, {
    [ModuleTag]: name
  });
};
var getModuleTag = (capability) => {
  return capability && typeof capability === "function" && ModuleTag in capability ? String(capability[ModuleTag]) : void 0;
};
var makeModule = (fn) => fn;

export {
  Service,
  get,
  getAll,
  waitFor,
  atom,
  ModuleTag,
  make,
  contributes,
  lazy,
  getModuleTag,
  makeModule,
  capability_exports
};
//# sourceMappingURL=chunk-64IMLAS2.mjs.map
