# Entry and Registration

## activate(api)

The function your entry file exports. Cowork calls it once each time it starts the Extension's process.

```js
export function activate(api) {
  api.registerService({ id: 'sync', start: 'auto', async run(ctx) { /* ... */ } });
  return () => { /* optional cleanup */ };
}
```

### Parameters

| Name | Type | Description |
|---|---|---|
| `api` | `DozinAPI` | The registration functions below |

### Returns

Nothing, or a cleanup function (it may be async), or a promise of either. The cleanup function runs when the process stops and must be safe to call more than once.

### Limits

- `activate` has 5 seconds. Start timers and connections in a Connector's `start` or a task's `run`, not here.
- If it throws or times out, the Extension shows as failed in **Settings › Extensions**.

## api.registerConnector(definition)

Registers a Connector: the part that carries messages between an outside channel and Cowork's Gateway.

### Parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `definition` | `ConnectorDefinition` | Yes | See [Connector](https://docs.micromeet.ai/extension-sdk/connector.md) |

### Returns

Nothing.

### Throws

| Error | When |
|---|---|
| `TypeError` | `start`, `stop` or `send` missing; `id` not lowercase letters, digits and hyphens; `systemPrompt` over 4000 characters; invalid `chat` |
| `CapabilityDeniedError` | Called after `activate` has returned; `dozin.connectors` lists ids and this `id` is not one of them; the same `id` twice; more than 16 Connectors when `dozin.connectors` is not given |

In 0.1.41 the id must be listed in `dozin.connectors` (an empty list refuses every Connector), and `systemPrompt` and `chat` do not exist yet.

### Example

```js
api.registerConnector({ id: 'demo', start(ctx) {}, stop() {}, async send() { return { ok: true }; } });
```

## api.registerService(definition) <Badge type="warning" text="Not yet released" />

Registers a background task. It shows under the Extension in **Settings › Extensions**, where the person (or the AI with `local_service`) can start and stop it.

### Parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `definition` | `ServiceDefinition` | Yes | See [Background Tasks](https://docs.micromeet.ai/extension-sdk/service.md) |

### Returns

Nothing.

### Throws

| Error | When |
|---|---|
| `TypeError` | No `run` function, or a field of the definition is invalid (the message says which) |
| `CapabilityDeniedError` | Called after `activate` has returned; `service` is not in `dozin.capabilities`; the same `id` twice; more than 8 tasks |

### Example

```js
api.registerService({ id: 'sync', name: 'Sync', start: 'auto', async run(ctx) { /* ... */ } });
```

## api.log(text)

Writes one line to the Extension's log, which the person opens from **Settings › Extensions**.

| Name | Type | Required | Description |
|---|---|---|---|
| `text` | `string` | Yes | The line |

Returns nothing.

```js
api.log('activated');
```

## Related

- [Connector](https://docs.micromeet.ai/extension-sdk/connector.md): The definition passed to `registerConnector`
- [Background Tasks](https://docs.micromeet.ai/extension-sdk/service.md): The definition passed to `registerService`
