<!-- AANCER Developer Guide (English), step by step, part 3 of 3. All parts: https://aancer.ai/dev/llms.txt -->

## Build an embedded app

Your own web application appears inside AANCER. It stays on your own server.

> need: the licence feature Embedded apps.

### Prepare your server

1. Give the app its own https address, for example `https://planner.example.com`.
2. Let its pages send this header, with the address of AANCER:

```text
Content-Security-Policy: frame-ancestors https://aancer.example.com
```

3. Remove `X-Frame-Options` if your server sends it.

### Write the pack

1. Put this item into the manifest:

```
{ "kind": "app", "schemaVersion": 2, "id": "shift-board", "scope": "workspace",
  "workspace": "{{param.target_workspace}}",
  "spec": {
    "id": "shift-board", "title": "Shift board", "icon": "Table",
    "group": "Operations", "order": 31,
    "url": "https://planner.example.com/board.html",
    "origin": "https://planner.example.com",
    "sso": { "mode": "none" },
    "capabilities": ["read:dataset:shift_plan"],
    "egress": { "hosts": [] },
    "embed": { "sandbox": ["allow-scripts", "allow-same-origin"] } } }
```

2. Ask only for what the app needs:

| Capability | Allows the app to |
|-|-|
| `read:me` | know who the user is |
| `read:dataset:<id>` | read a dataset |
| `write:dataset:<id>` | write into a dataset |
| `query:model:<id>` | ask a model of a dashboard |
| `navigate` | open another page |
| `notify` | show a short message |

### Read data in your page

1. Take `bridge.js` from the example `examples/apps/shift-board`.
2. Connect and read:

```
const PLATFORM = 'https://aancer.example.com';
const bridge = await AancerBridge.connect({ platformOrigin: PLATFORM });
const result = await bridge.call('read:dataset', { datasetId: 'shift_plan', limit: 100 });
render(result.rows);
```

### Install and approve

1. Sign, import, activate.
2. Open the pack and choose **Manage app**.
3. Read what the app wants and choose **Approve**.
4. If it uses sign-in, choose **Create app secret** and give the secret to the person who runs the app server. It is shown once.
5. Open the app under **Dashboards**.

### Know who the user is (sign-in)

Use `"sso": { "mode": "code" }`. The complete program is in `examples/apps/shift-planner`. This is what happens:

1. Your server makes a secret pair (PKCE) and gives one half to the page.
2. The page says hello to AANCER and receives a code. It is valid for 60 seconds, once.
3. Your server exchanges the code for a token at `/api/apps/oauth/token`.
4. Your server checks the token at `/api/apps/introspect`. The answer says who it is.

> warn: Keep the app secret and the token on the server. Never send them to the browser. Do not use the role to decide what somebody may do.

## Build a connector

A connector links another system. It runs inside AANCER, so AANCER signs it, not you.

### Write it

1. Copy `examples/connectors/example-echo`.
2. Change `src/index.ts`:

```
import { createConnector, createAction, Property, ConnectorAuth } from '@aancer/connector-framework';

const echo = createAction({
  name: 'echo',
  displayName: 'Echo',
  description: 'Returns the text you send.',
  props: { text: Property.ShortText({ displayName: 'Text', required: true }) },
  async run({ propsValue }) { return { text: propsValue.text }; },
});

export const connector = createConnector({
  displayName: 'Example echo',
  auth: ConnectorAuth.None(),
  minimumSupportedRelease: '0.82.0',
  logoUrl: 'https://cdn.example.com/echo.png',
  authors: ['acme'],
  actions: [echo],
  triggers: [],
});
```

3. Name the hosts it calls in `pack.json` under `egressHosts`. A `*` alone is not allowed.
4. If every customer runs the system themselves, use `egressFromConnection` instead.
5. Build and test it with the connector kit on your own computer.

### Check before you submit

- No install scripts in any dependency
- No native add-ons
- `npm audit --omit=dev` finds nothing
- Only these licences: MIT, ISC, BSD-2-Clause, BSD-3-Clause, Apache-2.0, 0BSD
- `package-lock.json` is included

### Submit and install

1. Submit the source through [aancer.ai/partners](https://aancer.ai/partners).
2. You get back a signed `.ancpack` file.
3. Choose **Connectivity** > **Connectors** > **Add from files** and pick it.
4. Choose **Enable**. Only now may it reach its hosts.
5. Create a connection and use it.

## Use the API and the MCP server

### Call the API

Every page of AANCER uses the API under `/api`. You sign in with a token from your sign-in service.

1. Put the token into `TOKEN`.
2. Call, for example:

```
export AANCER=https://aancer.example.com

# import a pack
curl -X POST "$AANCER/api/extensions/packs/import" \
  -H "Authorization: Bearer $TOKEN" \
  --data-binary @acme.business-skills-1.0.0.ancpack

# activate it
curl -X POST "$AANCER/api/extensions/packs/acme.business-skills/activate" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"version":"1.0.0"}'
```

| What | Where |
|-|-|
| Packs | `/api/extensions` |
| Agents | `/api/agents` |
| Workflows | `/api/automations` |
| Skills | `/api/skills` |
| Dashboards | `/api/dashboards`, `/api/models`, `/api/widgets` |
| Hooks | `/api/event-hooks` |
| Apps | `/api/apps` |

If a right is missing, the answer is 403 and names it.

### Let another AI program use your agents

> need: the licence features for the MCP server and chat surfaces, and the right `mcp.tokens_own`.

1. Create a personal MCP token (right `mcp.tokens_own`), or ask an administrator for one.
2. Copy it. It is shown once.
3. Enter this in the other program:

```
{ "mcpServers": {
    "aancer": {
      "type": "http",
      "url": "https://aancer.example.com/mcp/v1",
      "headers": { "Authorization": "Bearer mcp_..." } } } }
```

4. Ask there: "Use find_agent to find the invoice agent, then ask it to summarise this week's open invoices."

If an agent wants to change something, the answer is "approval required" with a link. A person decides in AANCER.

## Publish in the certified catalog

1. Become a partner at [aancer.ai/partners](https://aancer.ai/partners).
2. Add these two blocks to the manifest:

```
"listing": { "v": 1, "summary": "Sorts incoming invoices.", "category": "finance" },
"declarations": {
  "v": 1, "licence": "LicenseRef-Acme-Commercial",
  "dataFlows": [ { "purpose": "Read invoices to extract amounts", "data": ["invoice-documents"],
                   "personalData": true, "destination": "installation" } ],
  "egress": [],
  "aiUse": { "intendedPurpose": "Drafts a proposal a person approves",
             "annexIII": false, "humanOversight": "approval-step" },
  "attestations": { "ownsRights": true, "noProhibitedPractice": true } }
```

3. Check the pack:

```bash
aancer-pack lint manifest.json content/
```

4. Correct every line it prints.
5. Submit the pack. AANCER checks and certifies it.

> warn: The two statements under `attestations` are legally important: you own the rights, and there is no prohibited practice. Only confirm what is true.

## When something does not work

| Message | What to do |
|-|-|
| `PACK_UNSIGNED` | Sign the pack |
| `PACK_SIGNATURE_INVALID` | A file changed after signing, or an unused file is in `content/`. Sign again |
| `PACK_SIGNER_UNKNOWN` | The administrator adds your public key |
| `PACK_SIGNER_NOT_ALLOWED` | It is a connector. Submit it |
| `PACK_SCHEMA_INVALID` | Read the path in the message and correct that field |
| `PACK_VERSION_CONFLICT` | Raise `version` |
| `PACK_PLATFORM_INCOMPATIBLE` | Correct `requires.platform`, or update the installation |
| `PACK_PARAMETER_MISSING` | Fill in the parameters when activating |
| `EXTENSION_REFERENCED` | Remove what depends on it first |
| `TPL_RESIDUAL_BINDING` | A step still holds an id. Use a parameter |
| `TPL_SECRET_FOUND` | Remove the password or key |
| `TPL_AIACT_REQUIRED` | Set risk class and purpose |
| `AGENT_BLUEPRINT_REF` | Knowledge must be a parameter; workflow and agent must be in the pack |
| `HOOK_HANDLER_INACTIVE` | Publish the workflow with an event trigger, then enable the hook |
| `THEME_ILLEGIBLE` | Choose colours with more contrast |
| `APP_EMBED_REFUSED` | Correct the header of the app |
| `APP_ORIGIN_UNAPPROVED` | An administrator approves the app |
| 403 Permission denied | The answer names the missing right |

All messages are in the **AANCER Developer Reference**.

### Checklist before you deliver

- The pack was tested in a test installation
- `aancer-pack verify` prints OK
- `version` was raised
- No passwords, keys or ids of an installation inside
- Workspaces and connections are parameters
- Removing and installing again works
- The customer has your public key and key id
- You told the customer which rights and licence features are needed

End of AANCER Developer Guide (English), step by step. All parts: https://aancer.ai/dev/llms.txt
