@nelsonlongxiang/dsh-open-a2a-net 0.6.28 → 0.6.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +87 -14
  2. package/README_zh.md +83 -7
  3. package/assets/nexusDist/assets/index-C_x3iAth.js +9 -0
  4. package/assets/nexusDist/assets/index-Dz8N80tI.css +1 -0
  5. package/assets/nexusDist/index.html +2 -2
  6. package/cli/a2a.mjs +0 -0
  7. package/cordis.patch.yml +21 -21
  8. package/lib/canvas-store.js +21 -1
  9. package/lib/client.js +64 -64
  10. package/lib/client.js.map +1 -1
  11. package/lib/faces/admin.js +755 -0
  12. package/lib/faces/canvas-notify.js +138 -0
  13. package/lib/faces/wire.js +669 -0
  14. package/lib/flood-guard.js +106 -0
  15. package/lib/index.js +200 -1392
  16. package/lib/recursion-guard.js +78 -0
  17. package/lib/runtime.js +1 -0
  18. package/lib/skill/SKILL.md +35 -9
  19. package/lib/skill/references/cli.md +24 -7
  20. package/lib/skill/references/collaboration.md +355 -0
  21. package/lib/skill/references/discovery.md +5 -2
  22. package/lib/skill/references/pitfalls.md +2 -1
  23. package/lib/skill/references/routing.md +18 -8
  24. package/lib/skill/references/setup.md +152 -0
  25. package/lib/task-ledger.js +40 -4
  26. package/lib/types/canvas-store.d.ts +10 -1
  27. package/lib/types/faces/admin.d.ts +133 -0
  28. package/lib/types/faces/canvas-notify.d.ts +74 -0
  29. package/lib/types/faces/wire.d.ts +171 -0
  30. package/lib/types/flood-guard.d.ts +29 -0
  31. package/lib/types/index.d.ts +11 -3
  32. package/lib/types/recursion-guard.d.ts +56 -0
  33. package/lib/types/runtime.d.ts +35 -0
  34. package/lib/types/task-ledger.d.ts +15 -1
  35. package/nexus-stage/package-lock.json +2262 -2262
  36. package/nexus-stage/src/canvas-ops.ts +175 -175
  37. package/nexus-stage/src/canvas-wire.ts +156 -156
  38. package/nexus-stage/src/edges.ts +72 -72
  39. package/nexus-stage/src/federation-overlay.ts +103 -103
  40. package/nexus-stage/src/federation.ts +240 -240
  41. package/nexus-stage/src/layout-doc.ts +143 -143
  42. package/nexus-stage/src/layout-wire.ts +158 -158
  43. package/nexus-stage/src/main.ts +5 -1
  44. package/nexus-stage/src/planning-card-text.ts +73 -0
  45. package/nexus-stage/src/planning-edges.ts +26 -0
  46. package/nexus-stage/src/planning-fit.ts +45 -0
  47. package/nexus-stage/src/planning-legend.ts +38 -0
  48. package/nexus-stage/src/planning-mirror.ts +31 -0
  49. package/nexus-stage/src/planning-overlap.ts +159 -0
  50. package/nexus-stage/src/planning-relayout.ts +121 -0
  51. package/nexus-stage/src/planning-search.ts +168 -0
  52. package/nexus-stage/src/planning-types.ts +1 -0
  53. package/nexus-stage/src/planning-undo.ts +68 -0
  54. package/nexus-stage/src/planning-view.ts +120 -121
  55. package/nexus-stage/src/planning.css +41 -8
  56. package/nexus-stage/src/seat.ts +35 -35
  57. package/nexus-stage/src/stage-name.ts +13 -13
  58. package/nexus-stage/src/tokens.ts +31 -31
  59. package/nexus-stage/src/viewport.ts +24 -1
  60. package/nexus-stage/src/wb-chat.ts +20 -6
  61. package/nexus-stage/src/wb-ledger.ts +20 -7
  62. package/nexus-stage/src/wb-names.ts +43 -0
  63. package/nexus-stage/src/workbench.css +8 -2
  64. package/nexus-stage/src/workbench.ts +55 -17
  65. package/nexus-stage/src/world.ts +13 -21
  66. package/package.json +216 -214
  67. package/assets/nexusDist/assets/index-1niOBYxp.js +0 -5
  68. package/assets/nexusDist/assets/index-uQf7NwjF.css +0 -1
  69. package/nexus-stage/scripts/__pycache__/mockhost.cpython-312.pyc +0 -0
@@ -1,240 +1,240 @@
1
- /**
2
- * Federation overlay geometry for the 2D planning canvas (PR D 活动/联邦
3
- * 层): where peer badges sit, which accent edges carry the pending a2a
4
- * routes, and where the indigo federal referral lines attach. Everything
5
- * is derived from the polling state (`/__dsh_a2a/state` -> inFlight,
6
- * peers) plus the team-frame anchors, so the DOM layer only draws what
7
- * these functions return - same derivation discipline as edges.ts.
8
- *
9
- * Pure: no DOM, no three, no clock. `now` is always a parameter so the
10
- * suite pins time deterministically. All coordinates are world-space;
11
- * the transformed #world container carries them to the screen for free.
12
- * @module nexus-stage/federation
13
- */
14
-
15
- import type { WorldBounds } from './viewport'
16
-
17
- /** One pending outbound route from /state `inFlight`. */
18
- export interface InFlightRow {
19
- team: string
20
- /** peer as `host:port` (no scheme) - the badge url carries the scheme. */
21
- peer: string
22
- startedAt: number
23
- }
24
-
25
- /** One federation peer from /state `peers`. */
26
- export interface PeerRow {
27
- url: string
28
- score?: number
29
- /** gh#20 W-A: this host's link view — 'linked' (operator-established
30
- * basis holds) | 'stranger' (no link); absent = the host predates the
31
- * field (render neutral). */
32
- link?: 'linked' | 'stranger'
33
- /** Signature-valid cached card held (the badge tick/cross). */
34
- verified?: boolean
35
- }
36
-
37
- /** A team frame's titlebar anchor {fx + fw/2, fy + 11} (edges.ts lockstep). */
38
- export interface FrameAnchor {
39
- name: string
40
- x: number
41
- y: number
42
- }
43
-
44
- /** A peer badge's resolved slot in the placement column. */
45
- export interface PeerPlacement {
46
- url: string
47
- score?: number
48
- x: number
49
- y: number
50
- }
51
-
52
- /** One derived overlay edge, ready for the SVG / label layers. */
53
- /** Node id for a peer endpoint: `peer-<host>:<port>` (≤128, no '/').
54
- * Unparseable urls keep their raw text, reduced to id-safe characters —
55
- * attacker-shaped urls collapse to one id instead of poisoning selectors. */
56
- export function peerNodeId(url: string): string {
57
- const host = peerHostOf(url).replace(/[^A-Za-z0-9.:\[\]-]/g, '-')
58
- return `peer-${host}`
59
- }
60
-
61
- /** Bare host:port of a peer url (scheme stripped; unparseable urls pass through). */
62
- export function peerHostOf(url: string): string {
63
- try {
64
- return new URL(url).host
65
- } catch {
66
- return url
67
- }
68
- }
69
-
70
- /** One remote team row as the directory reports it (state.remote). */
71
- export interface RemoteTeamRow {
72
- team: string
73
- name?: string
74
- via?: string
75
- workspace?: string
76
- /** Publishing node's label + LAN IP — the host grouping dimension. */
77
- origin?: string
78
- /** Roster teams the publishing node declared for this handle (card teamMemberships). */
79
- teams?: readonly string[]
80
- }
81
-
82
- /**
83
- * Group remote team rows by the peer endpoint they arrived through. Rows
84
- * without a usable `via` land under '' (skipped by peer card rendering).
85
- * Key = bare host:port.
86
- */
87
- export function groupRemoteTeams(rows: ReadonlyArray<RemoteTeamRow>): Map<string, RemoteTeamRow[]> {
88
- const out = new Map<string, RemoteTeamRow[]>()
89
- for (const row of rows) {
90
- const via = row.via !== undefined && row.via !== '' ? peerHostOf(row.via) : ''
91
- const list = out.get(via) ?? []
92
- list.push(row)
93
- out.set(via, list)
94
- }
95
- return out
96
- }
97
-
98
- export interface ActivityEdge {
99
- x1: number
100
- y1: number
101
- x2: number
102
- y2: number
103
- label: string
104
- }
105
-
106
- /** Badge column x-offset right of the frames' content bounds (maxX + gap). */
107
- export const PEER_COLUMN_GAP = 140
108
- /** Fallback column x while the canvas has no frames to anchor against. */
109
- export const PEER_COLUMN_FALLBACK_X = 200
110
- /** Vertical pitch between badges in the column. */
111
- export const PEER_COLUMN_STEP = 90
112
- /** Federal-line origin gap left of the content bounds (minX - gap). */
113
- /** Fallback federal anchor offset (null bounds): x = -GAP. */
114
- export const FEDERAL_ANCHOR_GAP = 80
115
- /** Gutter gap between the card field's right edge and the federal anchor
116
- * (bounds.maxX + GUTTER) — keeps the short stubs off the card field. */
117
- export const FEDERAL_GUTTER_GAP = 20
118
- /** Padding around every badge point when computing the fly region. */
119
- export const FLY_PAD = 60
120
-
121
- /**
122
- * Lay the peer badges out in a deterministic column: one x for all,
123
- * y stacked from the content bounds' top at a fixed 90px pitch, in the
124
- * peers array's order. Recomputed every reconcile - the column tracks
125
- * the content, never the mouse. Null bounds (empty canvas) fall back to
126
- * a fixed origin so first paint is still deterministic.
127
- */
128
- export function placePeers(
129
- peers: ReadonlyArray<PeerRow>,
130
- bounds: WorldBounds | null,
131
- ): PeerPlacement[] {
132
- const x = bounds !== null ? bounds.maxX + PEER_COLUMN_GAP : PEER_COLUMN_FALLBACK_X
133
- const y0 = bounds !== null ? bounds.minY : 0
134
- return peers.map((peer, i) => ({
135
- url: peer.url,
136
- score: peer.score,
137
- x,
138
- y: y0 + i * PEER_COLUMN_STEP,
139
- }))
140
- }
141
-
142
- /**
143
- * One accent edge per pending outbound route: from the route's team
144
- * frame titlebar anchor to the matching peer badge, labelled with the
145
- * route and its whole-second age. Rows whose team has no frame or whose
146
- * peer matches no badge are skipped - dangling rows are a polling
147
- * transient, not an error. Peer match is by suffix (`host:port` against
148
- * `scheme://host:port`), first badge in array order wins.
149
- */
150
- export function activityEdges(
151
- inFlight: ReadonlyArray<InFlightRow>,
152
- anchors: ReadonlyMap<string, FrameAnchor>,
153
- peers: ReadonlyArray<PeerPlacement>,
154
- now: number,
155
- ): ActivityEdge[] {
156
- // Merge identical (team, peer) routes into ONE edge: N concurrent routes
157
- // over the same span would stack perfectly opaque duplicates. The label
158
- // counts them (×N) and reports the OLDEST route's age — the one the user
159
- // has been waiting on longest.
160
- const merged = new Map<string, { team: string; peer: string; startedAt: number; count: number }>()
161
- for (const row of inFlight) {
162
- if (!anchors.has(row.team)) continue
163
- const key = `${row.team}\u0000${row.peer}`
164
- const cur = merged.get(key)
165
- if (cur === undefined) merged.set(key, { team: row.team, peer: row.peer, startedAt: row.startedAt, count: 1 })
166
- else {
167
- cur.startedAt = Math.min(cur.startedAt, row.startedAt)
168
- cur.count += 1
169
- }
170
- }
171
-
172
- const out: ActivityEdge[] = []
173
- for (const g of merged.values()) {
174
- const anchor = anchors.get(g.team)
175
- if (anchor === undefined) continue
176
- // Match by parsed host:port — a bare endsWith would let 'badhost:port'
177
- // satisfy a 'host:port' route.
178
- const badge = peers.find(p => { try { return new URL(p.url).host === g.peer } catch { return false } })
179
- if (badge === undefined) continue
180
- const elapsed = Math.max(0, Math.round((now - g.startedAt) / 1000))
181
- out.push({
182
- x1: anchor.x,
183
- y1: anchor.y,
184
- x2: badge.x,
185
- y2: badge.y,
186
- label: `a2a_route · ${g.peer} · ${elapsed}s` + (g.count > 1 ? ` ×${g.count}` : ''),
187
- })
188
- }
189
- return out
190
- }
191
-
192
- /**
193
- * Federal referral lines: from a content-bounds anchor (minX - 80,
194
- * vertical center) out to every peer badge. Only the first line is
195
- * labelled "gns referral" - one legend row, not one label per peer.
196
- * Null bounds anchors the fan at the fixed fallback origin.
197
- */
198
- export function federalEdges(
199
- peers: ReadonlyArray<PeerPlacement>,
200
- bounds: WorldBounds | null,
201
- ): ActivityEdge[] {
202
- // Gutter anchor: between the card field's right edge and the badge column,
203
- // at the badges' vertical mid — short stubs that cannot cross any card
204
- // (an anchor at the content's left middle raked long diagonals through
205
- // the whole field: the reported wiring anomaly).
206
- const anchor = bounds !== null
207
- ? { x: bounds.maxX + FEDERAL_GUTTER_GAP, y: peers.length > 0 ? (peers[0]!.y + peers[peers.length - 1]!.y) / 2 : (bounds.minY + bounds.maxY) / 2 }
208
- : { x: -FEDERAL_ANCHOR_GAP, y: 0 }
209
- return peers.map((peer, i) => ({
210
- x1: anchor.x,
211
- y1: anchor.y,
212
- x2: peer.x,
213
- y2: peer.y,
214
- label: i === 0 ? 'gns referral' : '',
215
- }))
216
- }
217
-
218
- /**
219
- * The fly region: frames' content bounds unioned with every badge point
220
- * padded by FLY_PAD, so a fit over it frames the whole federation
221
- * (canvas + column) with breathing room. Null only when there is
222
- * nothing at all to fly to.
223
- */
224
- export function flyBounds(
225
- bounds: WorldBounds | null,
226
- peers: ReadonlyArray<PeerPlacement>,
227
- ): WorldBounds | null {
228
- if (bounds === null && peers.length === 0) return null
229
- let minX = bounds !== null ? bounds.minX : Number.POSITIVE_INFINITY
230
- let minY = bounds !== null ? bounds.minY : Number.POSITIVE_INFINITY
231
- let maxX = bounds !== null ? bounds.maxX : Number.NEGATIVE_INFINITY
232
- let maxY = bounds !== null ? bounds.maxY : Number.NEGATIVE_INFINITY
233
- for (const peer of peers) {
234
- minX = Math.min(minX, peer.x - FLY_PAD)
235
- minY = Math.min(minY, peer.y - FLY_PAD)
236
- maxX = Math.max(maxX, peer.x + FLY_PAD)
237
- maxY = Math.max(maxY, peer.y + FLY_PAD)
238
- }
239
- return { minX, minY, maxX, maxY }
240
- }
1
+ /**
2
+ * Federation overlay geometry for the 2D planning canvas (PR D 活动/联邦
3
+ * 层): where peer badges sit, which accent edges carry the pending a2a
4
+ * routes, and where the indigo federal referral lines attach. Everything
5
+ * is derived from the polling state (`/__dsh_a2a/state` -> inFlight,
6
+ * peers) plus the team-frame anchors, so the DOM layer only draws what
7
+ * these functions return - same derivation discipline as edges.ts.
8
+ *
9
+ * Pure: no DOM, no three, no clock. `now` is always a parameter so the
10
+ * suite pins time deterministically. All coordinates are world-space;
11
+ * the transformed #world container carries them to the screen for free.
12
+ * @module nexus-stage/federation
13
+ */
14
+
15
+ import type { WorldBounds } from './viewport'
16
+
17
+ /** One pending outbound route from /state `inFlight`. */
18
+ export interface InFlightRow {
19
+ team: string
20
+ /** peer as `host:port` (no scheme) - the badge url carries the scheme. */
21
+ peer: string
22
+ startedAt: number
23
+ }
24
+
25
+ /** One federation peer from /state `peers`. */
26
+ export interface PeerRow {
27
+ url: string
28
+ score?: number
29
+ /** gh#20 W-A: this host's link view — 'linked' (operator-established
30
+ * basis holds) | 'stranger' (no link); absent = the host predates the
31
+ * field (render neutral). */
32
+ link?: 'linked' | 'stranger'
33
+ /** Signature-valid cached card held (the badge tick/cross). */
34
+ verified?: boolean
35
+ }
36
+
37
+ /** A team frame's titlebar anchor {fx + fw/2, fy + 11} (edges.ts lockstep). */
38
+ export interface FrameAnchor {
39
+ name: string
40
+ x: number
41
+ y: number
42
+ }
43
+
44
+ /** A peer badge's resolved slot in the placement column. */
45
+ export interface PeerPlacement {
46
+ url: string
47
+ score?: number
48
+ x: number
49
+ y: number
50
+ }
51
+
52
+ /** One derived overlay edge, ready for the SVG / label layers. */
53
+ /** Node id for a peer endpoint: `peer-<host>:<port>` (≤128, no '/').
54
+ * Unparseable urls keep their raw text, reduced to id-safe characters —
55
+ * attacker-shaped urls collapse to one id instead of poisoning selectors. */
56
+ export function peerNodeId(url: string): string {
57
+ const host = peerHostOf(url).replace(/[^A-Za-z0-9.:\[\]-]/g, '-')
58
+ return `peer-${host}`
59
+ }
60
+
61
+ /** Bare host:port of a peer url (scheme stripped; unparseable urls pass through). */
62
+ export function peerHostOf(url: string): string {
63
+ try {
64
+ return new URL(url).host
65
+ } catch {
66
+ return url
67
+ }
68
+ }
69
+
70
+ /** One remote team row as the directory reports it (state.remote). */
71
+ export interface RemoteTeamRow {
72
+ team: string
73
+ name?: string
74
+ via?: string
75
+ workspace?: string
76
+ /** Publishing node's label + LAN IP — the host grouping dimension. */
77
+ origin?: string
78
+ /** Roster teams the publishing node declared for this handle (card teamMemberships). */
79
+ teams?: readonly string[]
80
+ }
81
+
82
+ /**
83
+ * Group remote team rows by the peer endpoint they arrived through. Rows
84
+ * without a usable `via` land under '' (skipped by peer card rendering).
85
+ * Key = bare host:port.
86
+ */
87
+ export function groupRemoteTeams(rows: ReadonlyArray<RemoteTeamRow>): Map<string, RemoteTeamRow[]> {
88
+ const out = new Map<string, RemoteTeamRow[]>()
89
+ for (const row of rows) {
90
+ const via = row.via !== undefined && row.via !== '' ? peerHostOf(row.via) : ''
91
+ const list = out.get(via) ?? []
92
+ list.push(row)
93
+ out.set(via, list)
94
+ }
95
+ return out
96
+ }
97
+
98
+ export interface ActivityEdge {
99
+ x1: number
100
+ y1: number
101
+ x2: number
102
+ y2: number
103
+ label: string
104
+ }
105
+
106
+ /** Badge column x-offset right of the frames' content bounds (maxX + gap). */
107
+ export const PEER_COLUMN_GAP = 140
108
+ /** Fallback column x while the canvas has no frames to anchor against. */
109
+ export const PEER_COLUMN_FALLBACK_X = 200
110
+ /** Vertical pitch between badges in the column. */
111
+ export const PEER_COLUMN_STEP = 90
112
+ /** Federal-line origin gap left of the content bounds (minX - gap). */
113
+ /** Fallback federal anchor offset (null bounds): x = -GAP. */
114
+ export const FEDERAL_ANCHOR_GAP = 80
115
+ /** Gutter gap between the card field's right edge and the federal anchor
116
+ * (bounds.maxX + GUTTER) — keeps the short stubs off the card field. */
117
+ export const FEDERAL_GUTTER_GAP = 20
118
+ /** Padding around every badge point when computing the fly region. */
119
+ export const FLY_PAD = 60
120
+
121
+ /**
122
+ * Lay the peer badges out in a deterministic column: one x for all,
123
+ * y stacked from the content bounds' top at a fixed 90px pitch, in the
124
+ * peers array's order. Recomputed every reconcile - the column tracks
125
+ * the content, never the mouse. Null bounds (empty canvas) fall back to
126
+ * a fixed origin so first paint is still deterministic.
127
+ */
128
+ export function placePeers(
129
+ peers: ReadonlyArray<PeerRow>,
130
+ bounds: WorldBounds | null,
131
+ ): PeerPlacement[] {
132
+ const x = bounds !== null ? bounds.maxX + PEER_COLUMN_GAP : PEER_COLUMN_FALLBACK_X
133
+ const y0 = bounds !== null ? bounds.minY : 0
134
+ return peers.map((peer, i) => ({
135
+ url: peer.url,
136
+ score: peer.score,
137
+ x,
138
+ y: y0 + i * PEER_COLUMN_STEP,
139
+ }))
140
+ }
141
+
142
+ /**
143
+ * One accent edge per pending outbound route: from the route's team
144
+ * frame titlebar anchor to the matching peer badge, labelled with the
145
+ * route and its whole-second age. Rows whose team has no frame or whose
146
+ * peer matches no badge are skipped - dangling rows are a polling
147
+ * transient, not an error. Peer match is by suffix (`host:port` against
148
+ * `scheme://host:port`), first badge in array order wins.
149
+ */
150
+ export function activityEdges(
151
+ inFlight: ReadonlyArray<InFlightRow>,
152
+ anchors: ReadonlyMap<string, FrameAnchor>,
153
+ peers: ReadonlyArray<PeerPlacement>,
154
+ now: number,
155
+ ): ActivityEdge[] {
156
+ // Merge identical (team, peer) routes into ONE edge: N concurrent routes
157
+ // over the same span would stack perfectly opaque duplicates. The label
158
+ // counts them (×N) and reports the OLDEST route's age — the one the user
159
+ // has been waiting on longest.
160
+ const merged = new Map<string, { team: string; peer: string; startedAt: number; count: number }>()
161
+ for (const row of inFlight) {
162
+ if (!anchors.has(row.team)) continue
163
+ const key = `${row.team}\u0000${row.peer}`
164
+ const cur = merged.get(key)
165
+ if (cur === undefined) merged.set(key, { team: row.team, peer: row.peer, startedAt: row.startedAt, count: 1 })
166
+ else {
167
+ cur.startedAt = Math.min(cur.startedAt, row.startedAt)
168
+ cur.count += 1
169
+ }
170
+ }
171
+
172
+ const out: ActivityEdge[] = []
173
+ for (const g of merged.values()) {
174
+ const anchor = anchors.get(g.team)
175
+ if (anchor === undefined) continue
176
+ // Match by parsed host:port — a bare endsWith would let 'badhost:port'
177
+ // satisfy a 'host:port' route.
178
+ const badge = peers.find(p => { try { return new URL(p.url).host === g.peer } catch { return false } })
179
+ if (badge === undefined) continue
180
+ const elapsed = Math.max(0, Math.round((now - g.startedAt) / 1000))
181
+ out.push({
182
+ x1: anchor.x,
183
+ y1: anchor.y,
184
+ x2: badge.x,
185
+ y2: badge.y,
186
+ label: `a2a_route · ${g.peer} · ${elapsed}s` + (g.count > 1 ? ` ×${g.count}` : ''),
187
+ })
188
+ }
189
+ return out
190
+ }
191
+
192
+ /**
193
+ * Federal referral lines: from a content-bounds anchor (minX - 80,
194
+ * vertical center) out to every peer badge. Only the first line is
195
+ * labelled "gns referral" - one legend row, not one label per peer.
196
+ * Null bounds anchors the fan at the fixed fallback origin.
197
+ */
198
+ export function federalEdges(
199
+ peers: ReadonlyArray<PeerPlacement>,
200
+ bounds: WorldBounds | null,
201
+ ): ActivityEdge[] {
202
+ // Gutter anchor: between the card field's right edge and the badge column,
203
+ // at the badges' vertical mid — short stubs that cannot cross any card
204
+ // (an anchor at the content's left middle raked long diagonals through
205
+ // the whole field: the reported wiring anomaly).
206
+ const anchor = bounds !== null
207
+ ? { x: bounds.maxX + FEDERAL_GUTTER_GAP, y: peers.length > 0 ? (peers[0]!.y + peers[peers.length - 1]!.y) / 2 : (bounds.minY + bounds.maxY) / 2 }
208
+ : { x: -FEDERAL_ANCHOR_GAP, y: 0 }
209
+ return peers.map((peer, i) => ({
210
+ x1: anchor.x,
211
+ y1: anchor.y,
212
+ x2: peer.x,
213
+ y2: peer.y,
214
+ label: i === 0 ? 'gns referral' : '',
215
+ }))
216
+ }
217
+
218
+ /**
219
+ * The fly region: frames' content bounds unioned with every badge point
220
+ * padded by FLY_PAD, so a fit over it frames the whole federation
221
+ * (canvas + column) with breathing room. Null only when there is
222
+ * nothing at all to fly to.
223
+ */
224
+ export function flyBounds(
225
+ bounds: WorldBounds | null,
226
+ peers: ReadonlyArray<PeerPlacement>,
227
+ ): WorldBounds | null {
228
+ if (bounds === null && peers.length === 0) return null
229
+ let minX = bounds !== null ? bounds.minX : Number.POSITIVE_INFINITY
230
+ let minY = bounds !== null ? bounds.minY : Number.POSITIVE_INFINITY
231
+ let maxX = bounds !== null ? bounds.maxX : Number.NEGATIVE_INFINITY
232
+ let maxY = bounds !== null ? bounds.maxY : Number.NEGATIVE_INFINITY
233
+ for (const peer of peers) {
234
+ minX = Math.min(minX, peer.x - FLY_PAD)
235
+ minY = Math.min(minY, peer.y - FLY_PAD)
236
+ maxX = Math.max(maxX, peer.x + FLY_PAD)
237
+ maxY = Math.max(maxY, peer.y + FLY_PAD)
238
+ }
239
+ return { minX, minY, maxX, maxY }
240
+ }