@yaks/visualize 0.0.0-stage → 0.2.36
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.
- package/ActivityView.tsx +370 -0
- package/AnatomyList.tsx +183 -0
- package/Atlas.tsx +490 -0
- package/Detail.tsx +464 -0
- package/LICENSE +202 -0
- package/README.md +180 -2
- package/SectionHead.tsx +18 -0
- package/Topology.tsx +596 -0
- package/_dist/activity.d.ts +15 -0
- package/_dist/activity.d.ts.map +1 -0
- package/_dist/capture.d.ts +19 -0
- package/_dist/capture.d.ts.map +1 -0
- package/_dist/cli.d.ts +6 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/front.d.ts +6 -0
- package/_dist/front.d.ts.map +1 -0
- package/_dist/http.d.ts +21 -0
- package/_dist/http.d.ts.map +1 -0
- package/_dist/main.d.ts +2 -0
- package/_dist/main.d.ts.map +1 -0
- package/_dist/mod.d.ts +6 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/model.d.ts +55 -0
- package/_dist/model.d.ts.map +1 -0
- package/_dist/parts.d.ts +19 -0
- package/_dist/parts.d.ts.map +1 -0
- package/_dist/routes.d.ts +7 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/snapshot.d.ts +38 -0
- package/_dist/snapshot.d.ts.map +1 -0
- package/_dist/stream.d.ts +3 -0
- package/_dist/stream.d.ts.map +1 -0
- package/_dist/tools.d.ts +10 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/vocab.d.ts +5 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/activity.js +73 -0
- package/activity.js.map +1 -0
- package/activity.ts +104 -0
- package/capture.js +46 -0
- package/capture.js.map +1 -0
- package/capture.ts +68 -0
- package/cli.js +173 -0
- package/cli.js.map +1 -0
- package/cli.ts +200 -0
- package/deno.json +1 -0
- package/front.js +21 -0
- package/front.js.map +1 -0
- package/front.json +210 -0
- package/front.ts +22 -0
- package/http.js +290 -0
- package/http.js.map +1 -0
- package/http.ts +338 -0
- package/main.js +51 -0
- package/main.js.map +1 -0
- package/main.ts +50 -0
- package/mod.js +6 -0
- package/mod.js.map +1 -0
- package/mod.ts +15 -0
- package/model.js +551 -0
- package/model.js.map +1 -0
- package/model.ts +543 -0
- package/package.json +76 -4
- package/parts.js +70 -0
- package/parts.js.map +1 -0
- package/parts.ts +113 -0
- package/routes.js +53 -0
- package/routes.js.map +1 -0
- package/routes.ts +76 -0
- package/snapshot.js +117 -0
- package/snapshot.js.map +1 -0
- package/snapshot.ts +157 -0
- package/stream.js +73 -0
- package/stream.js.map +1 -0
- package/stream.ts +95 -0
- package/tools.js +64 -0
- package/tools.js.map +1 -0
- package/tools.ts +79 -0
- package/visualize.css +1787 -0
- package/vocab.js +13 -0
- package/vocab.js.map +1 -0
- package/vocab.json +97 -0
- package/vocab.ts +14 -0
package/model.ts
ADDED
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
/** The page's domain state lives in a local graph, not component state or a
|
|
2
|
+
* second record store. Resource indexes contain only bounded UUID mappings. */
|
|
3
|
+
import { computed, signal } from '@preact/signals-core'
|
|
4
|
+
import { client } from '@yaks/client'
|
|
5
|
+
import { desk, drafts } from '@yaks/draft'
|
|
6
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
7
|
+
import { derivedEid, mint } from '@yaks/graph/identity'
|
|
8
|
+
import { loadVocab } from '@yaks/vocab'
|
|
9
|
+
import type { Activity } from './activity.ts'
|
|
10
|
+
import { docs, draftDocs } from './front.js'
|
|
11
|
+
import { type Edge, located, type Node, parts, spine } from './parts.js'
|
|
12
|
+
import { GROUPS, type Snapshot } from './snapshot.js'
|
|
13
|
+
import { type Connection, type Source, stream, valid } from './stream.js'
|
|
14
|
+
|
|
15
|
+
export type { Activity, Edge, Node }
|
|
16
|
+
export type VisualizeState = {
|
|
17
|
+
selected: string
|
|
18
|
+
cause: string
|
|
19
|
+
filter: string
|
|
20
|
+
group: string
|
|
21
|
+
listPage: number
|
|
22
|
+
paused: boolean
|
|
23
|
+
view: 'map' | 'list'
|
|
24
|
+
theme: 'everforest' | 'rosepine'
|
|
25
|
+
scheme: 'dark' | 'light'
|
|
26
|
+
x: number
|
|
27
|
+
y: number
|
|
28
|
+
zoom: number
|
|
29
|
+
connected: Connection
|
|
30
|
+
gap: number
|
|
31
|
+
received: number
|
|
32
|
+
error: string
|
|
33
|
+
host: string
|
|
34
|
+
}
|
|
35
|
+
export type AtlasModel = {
|
|
36
|
+
readonly snapshot: {
|
|
37
|
+
peek: () => unknown
|
|
38
|
+
subscribe: (wake: () => void) => () => void
|
|
39
|
+
}
|
|
40
|
+
readonly state: VisualizeState
|
|
41
|
+
readonly nodes: Node[]
|
|
42
|
+
readonly edges: Edge[]
|
|
43
|
+
readonly events: Activity[]
|
|
44
|
+
readonly selected: Node | undefined
|
|
45
|
+
readonly cause: Activity[]
|
|
46
|
+
readonly coverage: Snapshot['coverage']['observed']
|
|
47
|
+
set: (patch: Partial<VisualizeState>) => void
|
|
48
|
+
search: (text: string) => void
|
|
49
|
+
select: (id: string) => void
|
|
50
|
+
/** A shared trace span ID, never an event-row UUID. */
|
|
51
|
+
choose: (id: string) => void
|
|
52
|
+
/** Handles failure internally; safe for a UI's void refresh(). */
|
|
53
|
+
refresh: () => Promise<void>
|
|
54
|
+
reset: () => void
|
|
55
|
+
close: () => void
|
|
56
|
+
}
|
|
57
|
+
export type ModelOptions = {
|
|
58
|
+
base?: string
|
|
59
|
+
fetch?: typeof fetch
|
|
60
|
+
connect?: (url: string) => Source
|
|
61
|
+
scheme?: 'dark' | 'light'
|
|
62
|
+
start?: boolean
|
|
63
|
+
}
|
|
64
|
+
let initial = (scheme: 'dark' | 'light'): VisualizeState => ({
|
|
65
|
+
selected: '',
|
|
66
|
+
cause: '',
|
|
67
|
+
filter: '',
|
|
68
|
+
group: 'all',
|
|
69
|
+
listPage: 0,
|
|
70
|
+
paused: false,
|
|
71
|
+
view: 'map',
|
|
72
|
+
theme: 'everforest',
|
|
73
|
+
scheme,
|
|
74
|
+
x: 0,
|
|
75
|
+
y: 0,
|
|
76
|
+
zoom: 1,
|
|
77
|
+
connected: 'connecting',
|
|
78
|
+
gap: 0,
|
|
79
|
+
received: 0,
|
|
80
|
+
error: '',
|
|
81
|
+
host: '',
|
|
82
|
+
})
|
|
83
|
+
let component = <T>(bundle: Bundle | undefined, key: string) =>
|
|
84
|
+
bundle?.[key] as T | undefined
|
|
85
|
+
let latest = (events: Activity[]) => {
|
|
86
|
+
let spans = new Map<string, Activity>()
|
|
87
|
+
for (let event of events) spans.set(event.id, event)
|
|
88
|
+
return spans
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Causality is limited to retained, same-epoch evidence. Missing parents are
|
|
92
|
+
* not guessed. Cycles cannot hang the surface. */
|
|
93
|
+
export let causes = (events: Activity[], id: string): Activity[] => {
|
|
94
|
+
let target = events.findLast((event) => event.id == id)
|
|
95
|
+
if (!target) return []
|
|
96
|
+
let spans = latest(events.filter((event) => event.epoch == target.epoch))
|
|
97
|
+
let included = new Set([id])
|
|
98
|
+
let parent = spans.get(id)?.parent
|
|
99
|
+
while (parent && spans.has(parent) && !included.has(parent)) {
|
|
100
|
+
included.add(parent)
|
|
101
|
+
parent = spans.get(parent)?.parent
|
|
102
|
+
}
|
|
103
|
+
for (let event of spans.values()) {
|
|
104
|
+
let seen = new Set<string>()
|
|
105
|
+
let at: string | undefined = event.id
|
|
106
|
+
while (at && !seen.has(at)) {
|
|
107
|
+
if (at == id) {
|
|
108
|
+
included.add(event.id)
|
|
109
|
+
break
|
|
110
|
+
}
|
|
111
|
+
seen.add(at)
|
|
112
|
+
at = spans.get(at)?.parent
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return [...spans.values()].filter((e) => included.has(e.id))
|
|
116
|
+
.sort((a, b) => a.seq - b.seq)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** All observations here are projections of the one producer stream. */
|
|
120
|
+
export let atlas = (opts: ModelOptions = {}): AtlasModel => {
|
|
121
|
+
let base = new URL(
|
|
122
|
+
opts.base ?? globalThis.location?.origin ??
|
|
123
|
+
'http://localhost',
|
|
124
|
+
)
|
|
125
|
+
let page = mint()
|
|
126
|
+
let stateId = derivedEid(`${page}|state`)
|
|
127
|
+
let actor = derivedEid(`${page}|actor`)
|
|
128
|
+
let local = client(loadVocab([...docs, ...draftDocs]), [drafts()], {
|
|
129
|
+
signal,
|
|
130
|
+
vault: false,
|
|
131
|
+
wireVault: false,
|
|
132
|
+
})
|
|
133
|
+
let closed = false
|
|
134
|
+
let request: AbortController | undefined
|
|
135
|
+
let feed: { close: () => void } | undefined
|
|
136
|
+
let resumed = false
|
|
137
|
+
let skipGap = false
|
|
138
|
+
let identities = new Map<string, string>()
|
|
139
|
+
// Fixed reusable record slots avoid a trail of deleted event tombstones.
|
|
140
|
+
let slots = Array.from({ length: 256 }, (_, i) => derivedEid(`${page}|${i}`))
|
|
141
|
+
let eventIds = new Map<string, string>()
|
|
142
|
+
let write = (bundles: Bundle[]) => {
|
|
143
|
+
if (closed || !bundles.length) return
|
|
144
|
+
let result = local.mutate(bundles)
|
|
145
|
+
if (result instanceof Promise) {
|
|
146
|
+
void result.catch(() => {
|
|
147
|
+
if (!closed) console.error('MRI local write')
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let patch = (value: Record<string, unknown>) =>
|
|
152
|
+
write([
|
|
153
|
+
{ entity: { eid: stateId }, Visualize: value },
|
|
154
|
+
])
|
|
155
|
+
let defaults = Object.fromEntries(
|
|
156
|
+
Object.entries(initial(opts.scheme ?? 'dark'))
|
|
157
|
+
.filter(([key]) => !['selected', 'cause', 'filter'].includes(key)),
|
|
158
|
+
)
|
|
159
|
+
write([{ entity: { eid: stateId }, Visualize: defaults }, {
|
|
160
|
+
entity: { eid: actor },
|
|
161
|
+
AtlasCoverage: { scope: 'page', observed: {} },
|
|
162
|
+
}])
|
|
163
|
+
let stateWatch = local.watch(`.entity.eid=${stateId}&.Visualize`)
|
|
164
|
+
let nodeWatch = local.watch('.AtlasPart')
|
|
165
|
+
let edgeWatch = local.watch('.AtlasRelation')
|
|
166
|
+
let eventWatch = local.watch('.AtlasEvent&.order=AtlasEvent.seq')
|
|
167
|
+
let coverageWatch = local.watch(`.entity.eid=${stateId}&.AtlasCoverage`)
|
|
168
|
+
let typed = desk({
|
|
169
|
+
mutate: (bundles) => closed ? [] : local.mutate(bundles),
|
|
170
|
+
watch: (query) => local.watch(query),
|
|
171
|
+
}, { by: () => closed ? undefined : actor, pace: 0 })
|
|
172
|
+
let identity = (id: string) => {
|
|
173
|
+
let eid = identities.get(id)
|
|
174
|
+
if (!eid) identities.set(id, eid = derivedEid(`${page}|part|${id}`))
|
|
175
|
+
return eid
|
|
176
|
+
}
|
|
177
|
+
let publicId = (eid?: string) => {
|
|
178
|
+
let row = eid ? local.ent(eid) : undefined
|
|
179
|
+
return component<Node>(row, 'AtlasPart')?.id ??
|
|
180
|
+
component<Edge>(row, 'AtlasRelation')?.id ?? ''
|
|
181
|
+
}
|
|
182
|
+
let rows = () => eventWatch.value
|
|
183
|
+
let observations = () =>
|
|
184
|
+
rows().map((b) => component<{ data: Activity }>(b, 'AtlasEvent')!.data)
|
|
185
|
+
let spanRef = (id: string) =>
|
|
186
|
+
rows().findLast((b) =>
|
|
187
|
+
component<{ span: string }>(b, 'AtlasEvent')?.span == id
|
|
188
|
+
)?.entity.eid ?? ''
|
|
189
|
+
let state = (): VisualizeState => {
|
|
190
|
+
let stored = component<VisualizeState>(stateWatch.value[0], 'Visualize')!
|
|
191
|
+
let cause = component<{ span: string }>(
|
|
192
|
+
stored.cause ? local.ent(stored.cause) : undefined,
|
|
193
|
+
'AtlasEvent',
|
|
194
|
+
)?.span ?? ''
|
|
195
|
+
return {
|
|
196
|
+
...initial(opts.scheme ?? 'dark'),
|
|
197
|
+
...stored,
|
|
198
|
+
selected: publicId(stored.selected),
|
|
199
|
+
cause,
|
|
200
|
+
filter: typed.text('anatomy-search'),
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
let clearEvents = (epoch: string) => {
|
|
204
|
+
write([
|
|
205
|
+
...rows().map((b): Bundle => ({ entity: b.entity, AtlasEvent: null })),
|
|
206
|
+
{
|
|
207
|
+
entity: { eid: stateId },
|
|
208
|
+
Visualize: { cause: null },
|
|
209
|
+
AtlasCoverage: { epoch },
|
|
210
|
+
},
|
|
211
|
+
])
|
|
212
|
+
eventIds.clear()
|
|
213
|
+
}
|
|
214
|
+
let epoch = (value: string) => {
|
|
215
|
+
let old = component<{ epoch?: string }>(
|
|
216
|
+
coverageWatch.value[0],
|
|
217
|
+
'AtlasCoverage',
|
|
218
|
+
)?.epoch
|
|
219
|
+
if (old == value) return
|
|
220
|
+
clearEvents(value)
|
|
221
|
+
if (old && !resumed) {
|
|
222
|
+
patch({ gap: state().gap + 1 })
|
|
223
|
+
skipGap = true
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let accept = (input: Activity) => {
|
|
227
|
+
if (closed || state().paused || !valid(input)) return
|
|
228
|
+
let known = component<{ epoch?: string }>(
|
|
229
|
+
coverageWatch.value[0],
|
|
230
|
+
'AtlasCoverage',
|
|
231
|
+
)?.epoch
|
|
232
|
+
if (known && known != input.epoch) return
|
|
233
|
+
if (!known) epoch(input.epoch)
|
|
234
|
+
let key = `${input.epoch}:${input.seq}`
|
|
235
|
+
if (eventIds.has(key)) return
|
|
236
|
+
let held = observations()
|
|
237
|
+
let chosen = state().cause
|
|
238
|
+
if (input.seq <= (held.at(-1)?.seq ?? 0)) return
|
|
239
|
+
if (!skipGap && held.length && input.seq > held.at(-1)!.seq + 1) {
|
|
240
|
+
patch({ gap: state().gap + 1 })
|
|
241
|
+
}
|
|
242
|
+
skipGap = false
|
|
243
|
+
let node = located(input, model.nodes)
|
|
244
|
+
let counts = input.counts && Object.fromEntries(
|
|
245
|
+
Object.entries(input.counts).filter(([name, n]) =>
|
|
246
|
+
name.length <= 64 && Number.isFinite(n)
|
|
247
|
+
).slice(0, 32),
|
|
248
|
+
)
|
|
249
|
+
let event: Activity = {
|
|
250
|
+
id: input.id,
|
|
251
|
+
parent: input.parent,
|
|
252
|
+
kind: input.kind,
|
|
253
|
+
name: input.name,
|
|
254
|
+
stage: input.stage,
|
|
255
|
+
time: input.time,
|
|
256
|
+
start: input.start,
|
|
257
|
+
duration: input.duration,
|
|
258
|
+
outcome: input.outcome,
|
|
259
|
+
package: input.package,
|
|
260
|
+
plugin: input.plugin,
|
|
261
|
+
counts,
|
|
262
|
+
seq: input.seq,
|
|
263
|
+
epoch: input.epoch,
|
|
264
|
+
node,
|
|
265
|
+
}
|
|
266
|
+
let next = [...held, event].slice(-256)
|
|
267
|
+
let used = new Set(eventIds.values())
|
|
268
|
+
let eid = held.length >= slots.length
|
|
269
|
+
? eventIds.get(`${held[0].epoch}:${held[0].seq}`)!
|
|
270
|
+
: slots.find((id) => !used.has(id))!
|
|
271
|
+
// Prune the transport UUID index at the same bound as the graph records.
|
|
272
|
+
let keys = new Set(next.map((e) => `${e.epoch}:${e.seq}`))
|
|
273
|
+
for (let old of eventIds.keys()) if (!keys.has(old)) eventIds.delete(old)
|
|
274
|
+
eventIds.set(key, eid)
|
|
275
|
+
let spans = latest(next)
|
|
276
|
+
let ref = (id?: string) => {
|
|
277
|
+
let at = id && spans.get(id)
|
|
278
|
+
return at ? eventIds.get(`${at.epoch}:${at.seq}`) ?? null : null
|
|
279
|
+
}
|
|
280
|
+
let bundles: Bundle[] = [{
|
|
281
|
+
entity: { eid },
|
|
282
|
+
AtlasEvent: {
|
|
283
|
+
seq: event.seq,
|
|
284
|
+
epoch: event.epoch,
|
|
285
|
+
span: event.id,
|
|
286
|
+
data: event,
|
|
287
|
+
node: node ? identity(node) : null,
|
|
288
|
+
parent: ref(event.parent),
|
|
289
|
+
},
|
|
290
|
+
}]
|
|
291
|
+
for (let row of rows()) {
|
|
292
|
+
if (row.entity.eid == eid) continue
|
|
293
|
+
let stored = component<{ parent?: string; data: Activity }>(
|
|
294
|
+
row,
|
|
295
|
+
'AtlasEvent',
|
|
296
|
+
)!
|
|
297
|
+
if (!keys.has(`${stored.data.epoch}:${stored.data.seq}`)) {
|
|
298
|
+
bundles.push({ entity: row.entity, AtlasEvent: null })
|
|
299
|
+
} else if ((stored.parent ?? null) != ref(stored.data.parent)) {
|
|
300
|
+
bundles.push({
|
|
301
|
+
entity: row.entity,
|
|
302
|
+
AtlasEvent: {
|
|
303
|
+
parent: ref(stored.data.parent),
|
|
304
|
+
},
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
bundles.push({
|
|
309
|
+
entity: { eid: stateId },
|
|
310
|
+
Visualize: {
|
|
311
|
+
received: state().received + 1,
|
|
312
|
+
cause: ref(chosen),
|
|
313
|
+
},
|
|
314
|
+
})
|
|
315
|
+
write(bundles)
|
|
316
|
+
}
|
|
317
|
+
let start = (tail = false) => {
|
|
318
|
+
if (closed || state().paused || feed) return
|
|
319
|
+
patch({ connected: 'connecting' })
|
|
320
|
+
try {
|
|
321
|
+
feed = stream({
|
|
322
|
+
url: new URL('/visualize/events', base).href,
|
|
323
|
+
tail,
|
|
324
|
+
connect: opts.connect ?? ((url) => new EventSource(url)),
|
|
325
|
+
epoch: (value) => {
|
|
326
|
+
epoch(value)
|
|
327
|
+
resumed = false
|
|
328
|
+
},
|
|
329
|
+
activity: accept,
|
|
330
|
+
gap: () => {
|
|
331
|
+
if (!resumed && !skipGap) patch({ gap: state().gap + 1 })
|
|
332
|
+
skipGap = true
|
|
333
|
+
},
|
|
334
|
+
status: (connected) => patch({ connected }),
|
|
335
|
+
error: () => patch({ error: 'Invalid observation frame.' }),
|
|
336
|
+
})
|
|
337
|
+
} catch {
|
|
338
|
+
patch({ connected: 'offline', error: 'Activity connection failed.' })
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
let model: AtlasModel = {
|
|
342
|
+
snapshot: computed(() => [
|
|
343
|
+
state(),
|
|
344
|
+
nodeWatch.value,
|
|
345
|
+
edgeWatch.value,
|
|
346
|
+
eventWatch.value,
|
|
347
|
+
coverageWatch.value,
|
|
348
|
+
]),
|
|
349
|
+
get state() {
|
|
350
|
+
return state()
|
|
351
|
+
},
|
|
352
|
+
get nodes() {
|
|
353
|
+
return nodeWatch.value.map((b) => component<Node>(b, 'AtlasPart')!)
|
|
354
|
+
},
|
|
355
|
+
get edges() {
|
|
356
|
+
return edgeWatch.value.map((b) => {
|
|
357
|
+
let edge = component<Edge>(b, 'AtlasRelation')!
|
|
358
|
+
return { ...edge, from: publicId(edge.from), to: publicId(edge.to) }
|
|
359
|
+
})
|
|
360
|
+
},
|
|
361
|
+
get events() {
|
|
362
|
+
return observations()
|
|
363
|
+
},
|
|
364
|
+
get selected() {
|
|
365
|
+
return model.nodes.find((n) => n.id == state().selected)
|
|
366
|
+
},
|
|
367
|
+
get cause() {
|
|
368
|
+
return causes(observations(), state().cause)
|
|
369
|
+
},
|
|
370
|
+
get coverage() {
|
|
371
|
+
return component<{ observed: AtlasModel['coverage'] }>(
|
|
372
|
+
coverageWatch.value[0],
|
|
373
|
+
'AtlasCoverage',
|
|
374
|
+
)?.observed ?? {}
|
|
375
|
+
},
|
|
376
|
+
set: (value) => {
|
|
377
|
+
if (closed) return
|
|
378
|
+
let { filter, selected, cause, ...rest } = value
|
|
379
|
+
if (filter != undefined) typed.type('anatomy-search', filter)
|
|
380
|
+
let before = state()
|
|
381
|
+
let next: Record<string, unknown> = { ...rest }
|
|
382
|
+
if (selected != undefined) {
|
|
383
|
+
next.selected = identities.get(selected) ?? null
|
|
384
|
+
}
|
|
385
|
+
if (cause != undefined) next.cause = spanRef(cause) || null
|
|
386
|
+
for (let k of ['x', 'y', 'zoom', 'listPage'] as const) {
|
|
387
|
+
if (value[k] != undefined && !Number.isFinite(value[k])) delete next[k]
|
|
388
|
+
}
|
|
389
|
+
if (typeof next.zoom == 'number') {
|
|
390
|
+
next.zoom = Math.max(.35, Math.min(3, next.zoom))
|
|
391
|
+
}
|
|
392
|
+
if (typeof next.listPage == 'number') {
|
|
393
|
+
next.listPage = Math.max(0, Math.floor(next.listPage))
|
|
394
|
+
}
|
|
395
|
+
if (value.paused != undefined && value.paused != before.paused) {
|
|
396
|
+
if (value.paused) {
|
|
397
|
+
feed?.close()
|
|
398
|
+
feed = undefined
|
|
399
|
+
next.connected = 'paused'
|
|
400
|
+
} else {
|
|
401
|
+
resumed = true
|
|
402
|
+
skipGap = true
|
|
403
|
+
next.gap = before.gap + 1
|
|
404
|
+
next.connected = 'connecting'
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
patch(next)
|
|
408
|
+
if (before.paused && value.paused === false) start(true)
|
|
409
|
+
},
|
|
410
|
+
search: (text) => {
|
|
411
|
+
if (!closed) typed.type('anatomy-search', text)
|
|
412
|
+
},
|
|
413
|
+
select: (id) => model.set({ selected: id }),
|
|
414
|
+
choose: (id) => model.set({ cause: id }),
|
|
415
|
+
reset: () => model.set({ x: 0, y: 0, zoom: 1 }),
|
|
416
|
+
refresh: async () => {
|
|
417
|
+
if (closed) return
|
|
418
|
+
request?.abort()
|
|
419
|
+
let stop = new AbortController()
|
|
420
|
+
request = stop
|
|
421
|
+
try {
|
|
422
|
+
let response = await (opts.fetch ?? fetch)(
|
|
423
|
+
new URL('/visualize/anatomy', base),
|
|
424
|
+
{
|
|
425
|
+
signal: stop.signal,
|
|
426
|
+
credentials: 'same-origin',
|
|
427
|
+
redirect: 'error',
|
|
428
|
+
},
|
|
429
|
+
)
|
|
430
|
+
if (!response.ok) throw new Error('anatomy refused')
|
|
431
|
+
let source = await response.json() as Snapshot
|
|
432
|
+
if (closed || stop.signal.aborted) return
|
|
433
|
+
if (
|
|
434
|
+
source.version != 1 || source.anatomy?.version != 1 ||
|
|
435
|
+
!source.coverage || !GROUPS.every((g) =>
|
|
436
|
+
Array.isArray(source.anatomy[g])
|
|
437
|
+
)
|
|
438
|
+
) throw new Error('bad anatomy')
|
|
439
|
+
let nodes = parts(source)
|
|
440
|
+
let nodeIds = new Set(nodes.map((n) => n.id))
|
|
441
|
+
let current = new Set([
|
|
442
|
+
...nodes.map((n) => n.id),
|
|
443
|
+
...source.anatomy.edges.map((e) => e.id),
|
|
444
|
+
])
|
|
445
|
+
let bundles: Bundle[] = []
|
|
446
|
+
for (let row of [...nodeWatch.value, ...edgeWatch.value]) {
|
|
447
|
+
let id = publicId(row.entity.eid)
|
|
448
|
+
if (!current.has(id)) {
|
|
449
|
+
bundles.push({
|
|
450
|
+
entity: row.entity,
|
|
451
|
+
AtlasPart: null,
|
|
452
|
+
AtlasRelation: null,
|
|
453
|
+
})
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
for (let node of nodes) {
|
|
457
|
+
bundles.push({ entity: { eid: identity(node.id) }, AtlasPart: node })
|
|
458
|
+
}
|
|
459
|
+
for (let edge of source.anatomy.edges) {
|
|
460
|
+
if (
|
|
461
|
+
!nodeIds.has(edge.from) || !nodeIds.has(edge.to)
|
|
462
|
+
) continue
|
|
463
|
+
bundles.push({
|
|
464
|
+
entity: { eid: identity(edge.id) },
|
|
465
|
+
AtlasRelation: {
|
|
466
|
+
...edge,
|
|
467
|
+
from: identity(edge.from),
|
|
468
|
+
to: identity(edge.to),
|
|
469
|
+
},
|
|
470
|
+
})
|
|
471
|
+
}
|
|
472
|
+
// Relink retained observations when lazy metadata arrives or a part
|
|
473
|
+
// leaves. The measurement, sequence and monotonic time are unchanged.
|
|
474
|
+
for (let row of rows()) {
|
|
475
|
+
let stored = component<{ data: Activity }>(row, 'AtlasEvent')!
|
|
476
|
+
let node = located(stored.data, nodes)
|
|
477
|
+
bundles.push({
|
|
478
|
+
entity: row.entity,
|
|
479
|
+
AtlasEvent: {
|
|
480
|
+
data: { ...stored.data, node },
|
|
481
|
+
node: node ? identity(node) : null,
|
|
482
|
+
},
|
|
483
|
+
})
|
|
484
|
+
}
|
|
485
|
+
bundles.push({
|
|
486
|
+
entity: { eid: stateId },
|
|
487
|
+
Visualize: {
|
|
488
|
+
host: source.coverage.scope,
|
|
489
|
+
error: '',
|
|
490
|
+
selected: current.has(state().selected)
|
|
491
|
+
? identities.get(state().selected) ?? null
|
|
492
|
+
: null,
|
|
493
|
+
},
|
|
494
|
+
AtlasCoverage: {
|
|
495
|
+
scope: source.coverage.scope,
|
|
496
|
+
observed: source.coverage.observed,
|
|
497
|
+
takenAt: source.takenAt,
|
|
498
|
+
},
|
|
499
|
+
})
|
|
500
|
+
write(bundles)
|
|
501
|
+
for (let id of identities.keys()) {
|
|
502
|
+
if (!current.has(id)) identities.delete(id)
|
|
503
|
+
}
|
|
504
|
+
} catch {
|
|
505
|
+
if (!closed && !stop.signal.aborted) {
|
|
506
|
+
patch({
|
|
507
|
+
error: 'Could not read host anatomy. Check access and retry.',
|
|
508
|
+
})
|
|
509
|
+
}
|
|
510
|
+
} finally {
|
|
511
|
+
if (request == stop) request = undefined
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
close: () => {
|
|
515
|
+
if (closed) return
|
|
516
|
+
closed = true
|
|
517
|
+
feed?.close()
|
|
518
|
+
feed = undefined
|
|
519
|
+
request?.abort()
|
|
520
|
+
typed.close()
|
|
521
|
+
for (
|
|
522
|
+
let watch of [
|
|
523
|
+
stateWatch,
|
|
524
|
+
nodeWatch,
|
|
525
|
+
edgeWatch,
|
|
526
|
+
eventWatch,
|
|
527
|
+
coverageWatch,
|
|
528
|
+
]
|
|
529
|
+
) watch.close()
|
|
530
|
+
identities.clear()
|
|
531
|
+
eventIds.clear()
|
|
532
|
+
local.close()
|
|
533
|
+
},
|
|
534
|
+
}
|
|
535
|
+
for (let node of spine()) {
|
|
536
|
+
write([{ entity: { eid: identity(node.id) }, AtlasPart: node }])
|
|
537
|
+
}
|
|
538
|
+
if (opts.start !== false) {
|
|
539
|
+
start()
|
|
540
|
+
void model.refresh()
|
|
541
|
+
}
|
|
542
|
+
return model
|
|
543
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/visualize",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/visualize",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./snapshot": {
|
|
12
|
+
"types": "./_dist/snapshot.d.ts",
|
|
13
|
+
"default": "./snapshot.js"
|
|
14
|
+
},
|
|
15
|
+
"./activity": {
|
|
16
|
+
"types": "./_dist/activity.d.ts",
|
|
17
|
+
"default": "./activity.js"
|
|
18
|
+
},
|
|
19
|
+
"./capture": {
|
|
20
|
+
"types": "./_dist/capture.d.ts",
|
|
21
|
+
"default": "./capture.js"
|
|
22
|
+
},
|
|
23
|
+
"./http": {
|
|
24
|
+
"types": "./_dist/http.d.ts",
|
|
25
|
+
"default": "./http.js"
|
|
26
|
+
},
|
|
27
|
+
"./front": {
|
|
28
|
+
"types": "./_dist/front.d.ts",
|
|
29
|
+
"default": "./front.js"
|
|
30
|
+
},
|
|
31
|
+
"./model": {
|
|
32
|
+
"types": "./_dist/model.d.ts",
|
|
33
|
+
"default": "./model.js"
|
|
34
|
+
},
|
|
35
|
+
"./routes": {
|
|
36
|
+
"types": "./_dist/routes.d.ts",
|
|
37
|
+
"default": "./routes.js"
|
|
38
|
+
},
|
|
39
|
+
"./cli": {
|
|
40
|
+
"types": "./_dist/cli.d.ts",
|
|
41
|
+
"default": "./cli.js"
|
|
42
|
+
},
|
|
43
|
+
"./tools": {
|
|
44
|
+
"types": "./_dist/tools.d.ts",
|
|
45
|
+
"default": "./tools.js"
|
|
46
|
+
},
|
|
47
|
+
"./vocab": {
|
|
48
|
+
"types": "./_dist/vocab.d.ts",
|
|
49
|
+
"default": "./vocab.js"
|
|
50
|
+
},
|
|
51
|
+
"./main": {
|
|
52
|
+
"types": "./_dist/main.d.ts",
|
|
53
|
+
"default": "./main.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"license": "Apache-2.0",
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@yaks/api": "0.2.36",
|
|
59
|
+
"@yaks/cli": "0.2.36",
|
|
60
|
+
"@yaks/client": "0.2.36",
|
|
61
|
+
"@yaks/code": "0.2.36",
|
|
62
|
+
"@yaks/draft": "0.2.36",
|
|
63
|
+
"@yaks/fp": "0.2.36",
|
|
64
|
+
"@yaks/graph": "0.2.36",
|
|
65
|
+
"@yaks/host": "0.2.36",
|
|
66
|
+
"@yaks/react": "0.2.36",
|
|
67
|
+
"@yaks/tools": "0.2.36",
|
|
68
|
+
"@yaks/trace": "0.2.36",
|
|
69
|
+
"@yaks/ui": "0.2.36",
|
|
70
|
+
"@yaks/ux": "0.2.36",
|
|
71
|
+
"@yaks/vocab": "0.2.36",
|
|
72
|
+
"@preact/signals-core": "1.14.5",
|
|
73
|
+
"@types/react": "19.3.0",
|
|
74
|
+
"react": "19.3.0"
|
|
75
|
+
},
|
|
76
|
+
"description": "A value-free atlas of a composed platform and its subscriber-owned live causal activity, on /visualize and through agent doors.",
|
|
77
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
78
|
+
}
|
package/parts.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Client projection of a supplied contract, never another composition mapper. */ import { GROUPS } from "./snapshot.js";
|
|
2
|
+
export let phases = [
|
|
3
|
+
'normalize',
|
|
4
|
+
'admit',
|
|
5
|
+
'mint',
|
|
6
|
+
'prepare',
|
|
7
|
+
'precondition',
|
|
8
|
+
'rules',
|
|
9
|
+
'mutate',
|
|
10
|
+
'cascade',
|
|
11
|
+
'stamp',
|
|
12
|
+
'journal',
|
|
13
|
+
'commit',
|
|
14
|
+
'effect',
|
|
15
|
+
'audit'
|
|
16
|
+
];
|
|
17
|
+
/** These labels explain the pipeline. They are not observed bound handlers. */ export let spine = ()=>phases.map((name, order)=>({
|
|
18
|
+
id: `phase:${name}`,
|
|
19
|
+
name,
|
|
20
|
+
group: 'phases',
|
|
21
|
+
declared: true,
|
|
22
|
+
loaded: false,
|
|
23
|
+
bound: false,
|
|
24
|
+
description: name == 'audit' ? 'Rollback notification, not the continuation of a successful apply.' : 'A pipeline label, not a claim that a handler is bound.',
|
|
25
|
+
detail: {
|
|
26
|
+
phase: name,
|
|
27
|
+
order,
|
|
28
|
+
path: name == 'audit' ? 'rollback' : 'apply'
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
export let parts = (source)=>[
|
|
32
|
+
...GROUPS.flatMap((group)=>source.anatomy[group].map((part)=>{
|
|
33
|
+
let { id, name, package: owner, facet, declared, loaded, bound, description, ...detail } = part;
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
name,
|
|
37
|
+
group,
|
|
38
|
+
package: owner,
|
|
39
|
+
facet,
|
|
40
|
+
declared,
|
|
41
|
+
loaded,
|
|
42
|
+
bound,
|
|
43
|
+
description,
|
|
44
|
+
detail: {
|
|
45
|
+
...detail,
|
|
46
|
+
observed: source.coverage.observed[group] === true
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
})),
|
|
50
|
+
...spine()
|
|
51
|
+
];
|
|
52
|
+
/** Resolve only exact, unambiguous declared names. Unknown is not inferred. */ export let located = (event, nodes)=>{
|
|
53
|
+
if (event.kind == 'phase') {
|
|
54
|
+
let name = event.name.split('.').at(-1);
|
|
55
|
+
if (phases.some((p)=>p == name)) return `phase:${name}`;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let group = {
|
|
59
|
+
rule: 'rules',
|
|
60
|
+
effect: 'effects',
|
|
61
|
+
request: 'routes'
|
|
62
|
+
}[event.kind];
|
|
63
|
+
let candidates = group ? nodes.filter((n)=>n.group == group && n.name == event.name && (!event.package || n.package == event.package)) : [];
|
|
64
|
+
if (candidates.length == 1) return candidates[0].id;
|
|
65
|
+
if (event.plugin || event.package) {
|
|
66
|
+
let owners = nodes.filter((n)=>n.group == 'packages' && n.name == (event.package ?? event.plugin));
|
|
67
|
+
if (owners.length == 1) return owners[0].id;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=parts.js.map
|
package/parts.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts.js","sources":["./parts.ts"],"names":[],"mappings":"AAAA,gFAAgF,GAEhF,SAAS,MAAM,wBAAsC;AAerD,OAAO,IAAI,SAAS;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAS;AAEV,6EAA6E,GAC7E,OAAO,IAAI,QAAQ,IACjB,OAAO,GAAG,CAAC,CAAC,MAAM,QAAU,CAAC;MAC3B,IAAI,CAAC,MAAM,EAAE,MAAM;MACnB;MACA,OAAO;MACP,UAAU;MACV,QAAQ;MACR,OAAO;MACP,aAAa,QAAQ,UACjB,uEACA;MACJ,QAAQ;QACN,OAAO;QACP;QACA,MAAM,QAAQ,UAAU,aAAa;MACvC;IACF,CAAC,GAAE;AAEL,OAAO,IAAI,QAAQ,CAAC,SAA6B;OAC5C,OAAO,OAAO,CAAC,CAAC,QACjB,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,EACF,EAAE,EACF,IAAI,EACJ,SAAS,KAAK,EACd,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,WAAW,EACX,GAAG,QACJ,GAAG;QACJ,OAAO;UACL;UACA;UACA;UACA,SAAS;UACT;UACA;UACA;UACA;UACA;UACA,QAAQ;YACN,GAAG,MAAM;YACT,UAAU,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,KAAK;UAChD;QACF;MACF;OAEC;GACJ,CAAA;AAED,6EAA6E,GAC7E,OAAO,IAAI,UAAU,CAAC,OAAc;EAClC,IAAI,MAAM,IAAI,IAAI,SAAS;IACzB,IAAI,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,IAAI,CAAC,CAAC,IAAM,KAAK,OAAO,OAAO,CAAC,MAAM,EAAE,MAAM;IACzD;EACF;EACA,IAAI,QACF,AAAC;IAAE,MAAM;IAAS,QAAQ;IAAW,SAAS;EAAS,CAGrD,CAAC,MAAM,IAAI,CAAC;EAChB,IAAI,aAAa,QACb,MAAM,MAAM,CAAC,CAAC,IACd,EAAE,KAAK,IAAI,SAAS,EAAE,IAAI,IAAI,MAAM,IAAI,IACxC,CAAC,CAAC,MAAM,OAAO,IAAI,EAAE,OAAO,IAAI,MAAM,OAAO,KAE7C,EAAE;EACN,IAAI,WAAW,MAAM,IAAI,GAAG,OAAO,UAAU,CAAC,EAAE,CAAC,EAAE;EACnD,IAAI,MAAM,MAAM,IAAI,MAAM,OAAO,EAAE;IACjC,IAAI,SAAS,MAAM,MAAM,CAAC,CAAC,IACzB,EAAE,KAAK,IAAI,cACX,EAAE,IAAI,IAAI,CAAC,MAAM,OAAO,IAAI,MAAM,MAAM;IAE1C,IAAI,OAAO,MAAM,IAAI,GAAG,OAAO,MAAM,CAAC,EAAE,CAAC,EAAE;EAC7C;AACF,EAAC"}
|