Files
picoclaw/examples/pico-echo-server/README.md
T
Amir Mamaghani 544940807f feat(pico): add pico_client outbound WebSocket channel (#1198)
* feat(pico): add pico_client outbound WebSocket channel

Add a client-mode counterpart to the existing pico server channel.
pico_client connects to a remote Pico Protocol WebSocket server,
enabling picoclaw to bridge messages with external Pico-compatible
services.

Includes config, factory registration, manager wiring, 8 unit tests,
and a minimal echo-server example for interactive testing.

* fix(pico): address PR #1198 review — goroutine leak, race, auth

- Add per-connection context cancel to picoConn to prevent pingLoop
  goroutine leak on disconnect
- Re-acquire mutex in StartTyping stop closure to avoid stale conn race
- Remove query-param token auth from echo server (header-only)
- Move ListenAndServe to main goroutine where log.Fatal is safe

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: replace ConsumeInbound with InboundChan select in client test

MessageBus does not expose a ConsumeInbound method. Use a select on
InboundChan() with context cancellation, matching the pattern used in
the bus package tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 20:43:40 +08:00

48 lines
1.2 KiB
Markdown

# pico-echo-server
Minimal Pico Protocol WebSocket server for testing the `pico_client` channel.
## Usage
```bash
go run ./examples/pico-echo-server -addr :9090 -token secret
```
### Flags
| Flag | Default | Description |
|----------|---------|------------------------------------|
| `-addr` | `:9090` | Listen address |
| `-token` | (none) | Auth token; empty disables auth |
## How it works
- Listens for WebSocket connections at `/ws`
- Authenticates via `Authorization: Bearer <token>` header or `?token=<token>` query param
- Prints received `message.send` content to stdout
- Responds to `ping` with `pong`
- Lines typed into stdin are broadcast as `message.create` to all connected clients
## Testing with pico_client
1. Start the server:
```bash
go run ./examples/pico-echo-server -token mytoken
```
2. Configure `pico_client` in your `config.json`:
```json
{
"channels": {
"pico_client": {
"enabled": true,
"url": "ws://localhost:9090/ws",
"token": "mytoken",
"session_id": "test-session"
}
}
}
```
3. Start picoclaw — the client connects and you can exchange messages interactively via stdin/stdout.