> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Function Library Extension Files and Code

## Article: Function Library Extension Files and Code

## Article Link: https://dev.wix.com/docs/site-extensions/function-libraries/function-library-extension-files-and-code.md

## Article Content:

# Function Library Extension Files and Code

A [function library](https://dev.wix.com/docs/overview/extensions-framework/site-extensions/function-libraries.md) is a manifest and an implementation file that describe the same set of functions:

- A `<name>.extension.ts` file that holds the [manifest](#manifest), which declares each function's name, parameters, and return type.
- A `<name>.ts` file that holds the [implementation](#implementation), the code that implements the functions.

Function libraries are currently only available for Studio Two sites.

## Manifest

The `<name>.extension.ts` file holds the manifest.

The manifest includes:

- `functions`: Functions the library exposes.
- `resources`: Where the implementation code lives.

For example, a generated price-formatting library declares 1 function and points to its implementation file:

```ts
import { extensions } from '@wix/custom-extensions';

export default extensions.functionLibrary({
  id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
  name: 'My Function Library',
  type: 'companionApp.myFunctionLibrary',
  functions: {
    formatPrice: {
      displayName: 'Format price',
      description: 'Formats an amount as a price string',
      parameters: [
        {
          dataType: 'number',
          displayName: 'Amount',
        },
        {
          dataType: 'text',
          displayName: 'Currency symbol',
          optional: true,
        },
      ],
      returns: {
        dataType: 'text',
        displayName: 'Formatted price',
      },
    },
  },
  resources: {
    client: {
      url: './extensions/site/function-libraries/my-function-library/my-function-library.ts',
    },
  },
});
```

The generated manifest has no `resources.moduleSpecifier`. Add one that starts with `@/`, as [Function Library Resources Reference](https://dev.wix.com/docs/site-extensions/function-libraries/function-library-resources-reference.md#module-specifier) describes.

For the full manifest reference, see [About the Function Library Manifest](https://dev.wix.com/docs/site-extensions/function-libraries/about-the-function-library-manifest.md).

## Implementation

The `<name>.ts` file holds the implementation.

It exports one function per entry in the manifest, matching it by name:

```ts
export function formatPrice(amount: number, currencySymbol = '$'): string {
  return `${currencySymbol}${amount.toFixed(2)}`;
}
```

The implementation and the manifest must agree:

- Export each function as a named export. Its name must match its key in `functions` exactly, including case. The editor offers every function in the manifest, so a key with no matching export has nothing to run.
- Accept the parameters in the order the manifest lists them, with the same types. An optional parameter in the manifest is an optional or default parameter in the code.
- Return a value of the manifest's `returns` type. If `async` is `true`, return a Promise of that type.
- Make an [event parameter](https://dev.wix.com/docs/site-extensions/function-libraries/function-reference.md#event-parameters) optional, and type it as a React `SyntheticEvent`. The function must also work without the event, because **On Click** doesn't pass it.

## See also

- [About Function Libraries](https://dev.wix.com/docs/site-extensions/function-libraries/about-function-libraries.md)
- [Function Libraries](https://dev.wix.com/docs/overview/extensions-framework/site-extensions/function-libraries.md)
- [Add a Function Library Extension in Studio Two](https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/add-a-function-library-extension-in-studio-two.md)
- [About the Function Library Manifest](https://dev.wix.com/docs/site-extensions/function-libraries/about-the-function-library-manifest.md)