# userdir_A1

## v059 notes
- Node-RED custom nodes use route `group.project.client#endpoint`; `room` is not part of routing.
- Import `flows_aiwk_ping_chat_v059_import.json` for ping/chat reply tests.
- `aiwk-in` now matches both canonical route and `aiwk://room@group.project.client#endpoint` target forms.

## v143-nodered-aiwk-url-debug-log (2026-06-14)

목적: Node-RED debug 로그에서 `aiwk://{room}@{group}.{project}.{client_id}:{route_key}#{endpoint}` 주소가 보이도록 보강한다.

수정 범위(Node-RED only):
- `nodes/aiwk-common.js`
  - `makeProtocolAddress()` 추가
  - `addressFromPacket()` 추가
  - Node-RED 내부 packet에서 from/to `aiwk://` 주소를 재구성한다.
- `nodes/aiwk-in.js`
  - 수신 packet을 `msg.aiwk_from_url`, `msg.aiwk_to_url`, `msg.aiwk_route_debug`에 추가한다.
- `nodes/aiwk-out.js`
  - 송신 packet에 `from_url`, `to_url`, `aiwk_url`, `route_debug`를 추가한다.
  - debug node가 `payload`만 보더라도 `payload.aiwk_from_url`, `payload.aiwk_to_url`, `payload.aiwk_route_debug`가 나오게 한다.
- `flows.json`
  - `aiwk_ping -> aiwk_pong` function 응답 payload에 request/reply `aiwk://` 주소와 route_debug를 포함한다.
  - `aiwk_chat -> aiwk_chat_ack` function 응답 payload에도 같은 route_debug를 포함한다.

기대 로그 예:
```js
{
  type: 'result',
  action: 'aiwk_pong',
  ok: 1,
  received_action: 'aiwk_ping',
  aiwk_from_url: 'aiwk://RE5ay2jRmY@home.IG_CRM.N1:nodrd#node-red',
  aiwk_to_url: 'aiwk://RE5ay2jRmY@home.IG_CRM.A1:064f3#ext4',
  aiwk_route_debug: {
    request_from: 'aiwk://RE5ay2jRmY@home.IG_CRM.A1:064f3#ext4',
    request_to: 'aiwk://RE5ay2jRmY@home.IG_CRM.N1:nodrd#node-red',
    reply_from: 'aiwk://RE5ay2jRmY@home.IG_CRM.N1:nodrd#node-red',
    reply_to: 'aiwk://RE5ay2jRmY@home.IG_CRM.A1:064f3#ext4'
  }
}
```


## v144-aiwk-target-route-debug-fix (2026-06-14)

- Node-RED debug 로그의 aiwk_to_url이 `A1:nodrd#ext4`처럼 잘못 표시되는 문제를 수정했다.
- 원인: `packet.route_key`는 Node-RED 자신(`N1:nodrd`)의 route_key인데, 대상 주소 생성 시 fallback으로 사용되어 EXT4 대상 주소에 섞였다.
- 수정: `addressFromPacket(..., "to")`에서는 `to_route_key / to_url_key / to_url5 / parsed target route / to_tab_id`만 사용하고, `packet.route_key/url_key`는 대상 fallback으로 사용하지 않는다.
- `aiwk://...` 원본 주소가 들어오면 `parseAiwkAddress()`로 route_key와 endpoint를 우선 보존한다.
- 기대 로그: `aiwk_from_url = aiwk://...N1:nodrd#node-red`, `aiwk_to_url = aiwk://...A1:<A1 route_key>#ext4` 형태.
