airi/integrations
Rin 6ad0a70c10
feat(photon-bot,stage-ui): add Photon iMessage integration and settings page (#3558)
## Summary

Add an iMessage channel integration powered by the Photon API
(`integrations/photon-bot`) and a matching **iMessage** module settings
page in Stage UI.

- `integrations/photon-bot` runs as a standalone process, listens to the
Photon Socket.IO event stream, and forwards each inbound iMessage text
to AIRI as `input:text` bound to `photon:<spaceId>:<agentUserId>`.
- The bot reads the character reply from `output:gen-ai:chat:message`,
strips stage control tokens (`<|ACT …|>`, `<|DELAY …|>`, and malformed
`<ACT …|>`), and sends the plain text back through the Photon REST API
with an idempotency key.
- Stage UI adds an **iMessage** card and settings page (`Settings →
Modules → iMessage`) that sends `enabled`, `projectId`, and `apiKey` to
the `photon` module over `module:configure`.

## Context

- Request: Add a Photon-backed iMessage bot on the same integration path
as `discord-bot`, with a Stage UI settings page so users can configure
and toggle it without restarting the bot.
- Scenario: A user connects a Photon project with a shared iMessage line
to a local AIRI instance and exchanges texts with the character over
iMessage.
- Scope: Turn-based plain text only. Attachments, stickers, voice
messages, and `group` payloads are ignored. Inline reply quoting and
tapback sentences are implemented in the bot, while Photon Beta does not
yet deliver `parentMessageId` on shared-line replies or iMessage tapback
events. Settings backup schema changes are kept out of scope.

## Change map

| Module | Before | After | Description |
| --- | --- | --- | --- |
| `integrations/photon-bot` | Absent | New standalone module
(`PhotonStream`, `PhotonAdapter`, text formatters, Valibot config,
README, unit tests) | Holds the Photon stream, persists the stream
cursor per project, sends read receipts and typing indicators, backs off
on 401/403, and applies live `module:configure` updates. |
| `packages/stage-ui` & `packages/stage-pages` | No iMessage / Photon
module | `usePhotonStore`, `MessagingPhoton` component,
`/settings/modules/messaging-photon` route, module list entry, and
data-maintenance reset hook | Lets users toggle iMessage integration
immediately, edit Photon project ID and API key, save live changes, and
reset credentials. |
| `packages/i18n` | No `messaging-photon` strings | English
`settings.pages.modules.messaging-photon.*` keys in `en/settings.yaml` |
Provides English UI copy only. Crowdin manages other locales. |
| `README.md`, `docs/README.zh-CN.md` | The feature list names Telegram
and Discord chat | The list also names iMessage chat | Tells readers
about the new channel. Other locales keep their own text. |

## Architecture and behavior

```mermaid
sequenceDiagram
  participant P as Photon API
  participant S as PhotonStream
  participant A as PhotonAdapter
  participant C as AIRI Server Channel
  participant U as Stage UI (iMessage page)

  U->>C: ui:configure (enabled, projectId, apiKey)
  C->>A: module:configure
  A->>S: reconnect with new credentials (or close when disabled)

  P->>S: delivery (message.received, seq)
  S->>A: onDelivery(event, seq)
  A->>P: markRead + setTyping(true)
  A->>C: input:text (required delivery, binding photon:spaceId:agentUserId)
  alt no consumer registered
    C-->>A: error (no consumer registered)
    A->>C: retry after 3s
  else reply received
    C-->>A: output:gen-ai:chat:message
    A->>P: setTyping(false)
    A->>P: sendText (idempotency-key: airi-reply:<messageId>)
    A->>A: save { cursor: seq, projectId } to state file
  end
```

## Boundaries and risks

| Invariant or boundary | Failure mode | Protection | Evidence or gap |
| --- | --- | --- | --- |
| Session isolation | Inbound iMessage joins the owner's private AIRI
chat session | Bind every `input:text` to
`photon:<spaceId>:<agentUserId>` and mask handles to last four digits |
Covered in `airi-adapter.test.ts` and `reply-text.test.ts` |
| Duplicate delivery on reconnect | Replay sends the same iMessage reply
twice | Persist cursor after `sendText` and pass `idempotency-key:
airi-reply:<messageId>` | Covered in `airi-adapter.test.ts` |
| Rejected API key (401 / 403) | Fast Socket.IO reconnect loop floods
logs and asks AIRI for unsent replies | Disconnect on 401/403 handshake
or HTTP refusal, log once, back off exponentially (30s to 10m), and
retry immediately on `module:configure` | Covered in
`airi-adapter.test.ts` |
| Project switch | Old project cursor skips events on a new project |
Store `projectId` beside `cursor` and reset cursor to `0` when
`projectId` changes | Covered in `airi-adapter.test.ts` |
| Inline replies and tapbacks | Photon Beta omits `parentMessageId` and
tapback events on shared lines | Documented in
`integrations/photon-bot/README.md`; quote lookup falls back to `"a
message"` | Unit-tested against documented OpenAPI shapes; live Photon
Beta delivery not yet available |
| UI settings state | Enabling without credentials or leaving stale
credentials after reset | Switch requires non-empty trimmed credentials,
applies immediately, and `resetState()` clears values and notifies
`photon` | Covered in
`packages/stage-ui/src/stores/modules/photon.test.ts` |

## Verification

- Manual happy-path check: Tested end-to-end on a shared Photon iMessage
line (inbound text, typing indicator, AIRI reply, outbound delivery, and
live settings toggle).
- Automated checks on `7f42b385a` (macOS arm64, Node 26.13.0, pnpm
11.24.0). The later commits change only `README.md`,
`docs/README.zh-CN.md`, and one lockfile metadata line.
  - `pnpm -F @proj-airi/photon-bot typecheck`: pass.
  - `pnpm -F @proj-airi/stage-ui typecheck`: pass.
  - `pnpm -F @proj-airi/stage-pages typecheck`: pass.
  - `pnpm typecheck`: pass.
  - `pnpm lint`: pass.
- `NODE_OPTIONS=--no-experimental-webstorage TURBO_SCM_BASE=32ffe96dc
pnpm exec turbo run test:run --affected`: `photon-bot` 33/33,
`stage-pages` 95/95, `stage-ui` 2245/2246. CI uses the same
`NODE_OPTIONS`.
- The one `stage-ui` failure is `keyframe-editor.browser.test.ts > drags
a keyframe and commits the drag once`. This PR does not change that
file. It passes 3 of 3 runs alone on this head and on the merge base.
  - CI on `e7177d8bf`: all checks pass.
- Visual captures: Before is the merge base `32ffe96dc`. After is the
code of this PR. All captures use `en`, and onboarding records set to
done.
- Stage Web and Stage Pocket: Vite dev servers. Vishot 0.2.0 direct
browser capture cannot seed `localStorage`. A disposable Playwright
script captured the routes with the Vishot context options. It hides the
Vue DevTools overlay of the dev server.
- Stage Pocket runs as a web page at mobile size. The native Capacitor
shell is not captured.
- Stage Tamagotchi: `electron-vite build`, then a disposable `vishot
capture --target electron` scenario. It opens Settings from the app menu
of the Island.
- The Modules captures scroll the Discord card to the center in both
revisions.
- The filled and switch-on states use the example values
`pho_prj_example` and `example-api-key`. No bot received them.

## Visual changes

### Stage Web (1440x900, device scale factor 2)

| Before | After |
| --- | --- |
|
![](https://github.com/user-attachments/assets/0f10ce85-fa43-405d-b463-84560e1e9dc1)
|
![](https://github.com/user-attachments/assets/1afdf907-2fa3-4111-8fc4-ddeb898fdba3)
|
| Settings / Modules, light | Settings / Modules, light |
|
![](https://github.com/user-attachments/assets/31a4373a-307c-42b7-a8c5-e6f945288134)
|
![](https://github.com/user-attachments/assets/94a9d318-ede5-45cd-94f6-8b3de9313642)
|
| Settings / Modules, dark | Settings / Modules, dark |
| Absent |
![](https://github.com/user-attachments/assets/9aedccad-7242-434e-b833-12c86e98d421)
|
| Settings / Modules / iMessage, empty, light | Settings / Modules /
iMessage, empty, light |
| Absent |
![](https://github.com/user-attachments/assets/af579a5e-211b-4e69-bd1f-6ea829fb6222)
|
| Settings / Modules / iMessage, empty, dark | Settings / Modules /
iMessage, empty, dark |
| Absent |
![](https://github.com/user-attachments/assets/a6ebb4f9-cd39-4a3d-8bb4-444b30de0dd5)
|
| Settings / Modules / iMessage, both values, switch off | Settings /
Modules / iMessage, both values, switch off |
| Absent |
![](https://github.com/user-attachments/assets/ddb70464-e241-4d70-b283-b9681ab40e46)
|
| Settings / Modules / iMessage, switch on | Settings / Modules /
iMessage, switch on |
| Absent |
![](https://github.com/user-attachments/assets/23188c59-5ebb-481a-b526-9054b5520a5b)
|
| Settings / Modules, iMessage on | Settings / Modules, iMessage on |

### Stage Tamagotchi (settings window, 600x800)

| Before | After |
| --- | --- |
|
![](https://github.com/user-attachments/assets/252d2687-4dff-40a3-8e4d-461e9641574f)
|
![](https://github.com/user-attachments/assets/3e7e36c4-3746-49ba-ad03-eddaa5e6847b)
|
| Settings / Modules | Settings / Modules |
| Absent |
![](https://github.com/user-attachments/assets/f2d563d7-5f50-4237-a74d-1c443fa05402)
|
| Settings / Modules / iMessage | Settings / Modules / iMessage |

### Stage Pocket (390x844, device scale factor 3, web page)

| Before | After |
| --- | --- |
|
![](https://github.com/user-attachments/assets/e7ce28e3-36fb-461f-b030-fa42f3f2f55b)
|
![](https://github.com/user-attachments/assets/59ccb1d9-3305-4073-969b-c7c3f6a21d64)
|
| Settings / Modules | Settings / Modules |
| Absent |
![](https://github.com/user-attachments/assets/444bd9d0-c704-4e45-8e64-bc06224c3b8e)
|
| Settings / Modules / iMessage | Settings / Modules / iMessage |

## Agent

- Harness: Claude Code
- Model: claude-opus-5-5
- Model: claude-fable-5-2

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-11-23 01:22:47 +00:00
..
discord-bot feat: add skills, long-term memory, and background tasks (#2748) 2026-10-15 14:32:10 +00:00
minecraft chore: upgrade injeca to 0.5.1 (#3436) 2026-11-08 06:41:31 +08:00
photon-bot feat(photon-bot,stage-ui): add Photon iMessage integration and settings page (#3558) 2026-11-23 01:22:47 +00:00
satori-bot Revert "style: lint" 2026-08-26 20:13:10 +08:00
telegram-bot refactor(telegram-bot): remove explicit any types (#3561) 2026-11-22 22:51:37 +09:00
twitter-services release: v0.15.4 2026-11-13 03:53:10 +07:00
vscode release: v0.15.4 2026-11-13 03:53:10 +07:00