# @evolutese/connectors

Built-in connectors for the Evolutese runtime — MongoDB and SMTP mail out of the box.

## Installation

```bash
npm install @evolutese/connectors
```

> `@evolutese/runtime` must also be installed (peer dependency).

---

## MongoConnector

Connects agents to MongoDB. Falls back to an **in-memory store** when no connection string is provided — catalog blueprints work out of the box without any infrastructure.

```typescript
import { buildMongoConnectorFromConfig } from '@evolutese/connectors';

const mongo = await buildMongoConnectorFromConfig({
  connectionString: process.env.MONGO_URI, // omit for in-memory fallback
  dbName: 'myapp',
});

await bootstrapRuntime({ connectors: { mongo } });
```

### In-memory mode (development / testing)

```typescript
import { InMemoryMongoConnector } from '@evolutese/connectors';

const mongo = new InMemoryMongoConnector();
// Data lives in memory — resets on process restart
```

### Real MongoDB

```typescript
import { MongoClient } from 'mongodb';
import { MongoConnector } from '@evolutese/connectors';

const client = new MongoClient(process.env.MONGO_URI);
await client.connect();
const mongo = new MongoConnector(client.db('myapp'));
```

### Agent YAML usage

```yaml
actions:
  - id: save_invoice
    connector: mongo
    params:
      collection: invoices
      insert: { customer: "{{customer}}", amount: "{{amount}}" }

  - id: list_invoices
    connector: mongo
    params:
      collection: invoices
      find: {}
```

Supported operations: `find`, `insert`, `update`, `delete`.

---

## MailConnector

Sends transactional email via SMTP. Falls back to simulation mode when no SMTP config is found.

```typescript
import { MailConnector } from '@evolutese/connectors';

await bootstrapRuntime({
  connectors: {
    mail: new MailConnector({
      host:   'smtp.example.com',
      port:   587,
      auth:   { user: 'user@example.com', pass: process.env.SMTP_PASS },
      from:   'no-reply@example.com',
    }),
  },
});
```

### Environment variables

| Variable | Default |
|----------|---------|
| `SMTP_HOST` | — (required for real delivery) |
| `SMTP_PORT` | `587` |
| `SMTP_SECURE` | `false` |
| `SMTP_USER` | — |
| `SMTP_PASS` | — |
| `SMTP_FROM` | `no-reply@evolutese.local` |

### Test connectivity

```typescript
const { success, message } = await new MailConnector().test();
```

---

## License

MIT
